Skip to content

Memory management #5509

Description

@KaiJun-Ma

Here is my code. I found that whenever I call 'invalidate', the memory keeps growing, and I need to update the chart frequently. Version 3.1.0

public void updateChart(float value) {
        // Add new data point
        try {
            Entry entry = mEntryPool.obtain();
            entry.setX(xAxis);
            entry.setY(value);
            entries.add(entry);

            // Notify the chart of data change and refresh
            if (System.currentTimeMillis()-lastRefreshTime > refreshDivision){
                dataSet.notifyDataSetChanged();
                lineData.notifyDataChanged();
                chart.notifyDataSetChanged();
                chart.invalidate();
                lastRefreshTime = System.currentTimeMillis();
            }

           // Keep only the latest MAX_DATA_POINTS
            if (entries.size() >= MAX_DATA_POINTS) {
                entry = entries.remove(0);
                mEntryPool.recycle(entry);
            }

            xAxis++;
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions