amcharts / amcharts4

The most advanced amCharts charting library for JavaScript and TypeScript apps.
https://www.amcharts.com/
1.15k stars 322 forks source link

XYChart: MemoryLeak with LiveData #1901

Open th3ragex opened 4 years ago

th3ragex commented 4 years ago

I am currently building a live chart based on your demo and experience increasing lags after several thousands of new values. The memory usage is steadily increasing.

Tested with Chrome 78.0.3904.97 @32Bit and Firefox 70.0.1 @64Bit

Please try it out: http://jsfiddle.net/vtur7s64/1/

Is there something i can do to lower the memory footprint?

martynasma commented 4 years ago

Does it get to a point where it starts slowing down or otherwise breaking down?

Browsers are designed to use up a lot of memory if it's available. So it might eat up a significant chunk of memory before GC mechanism even kicks in.

I've run the fiddle you provided for an hour. The memory usage was increasing for a while, until it capped out and did not grow anymore, which is a sign of healthy GC setup. It's not a memory leak.

If you know of steps on how to reproduce a memory leak (memory growing uncontrollably until the tab/browser becomes unusable), please do let me know.

th3ragex commented 4 years ago

Thank you for your feedback, i will try to isolate my chart code and test it again. I was a bit alarmed by the amount the memory is rising and the flickering on each animation in the 1GB region. Maybe it's caused by my Laptop which starts struggling after GC kicks in.

If i find something i will let you know.

th3ragex commented 4 years ago

@martynasma : I have modified the fiddle: http://jsfiddle.net/os4kn6yu/3/

After about 28 minutes the IFrame in Fiddle hosting the chart rose up to 1.2 GB Memory footprint (seen in chrome task manager) and crashed.

Note: Switching tabs, locking the PC or minimizing the Chrome window frees memory and/or stops the chart somehow. I had to leave it open/visible and untouched the whole time.

Are you able to reproduce this behavior too?

Screenshot of the task manager half way through: image

martynasma commented 4 years ago

OK, this is a wholly new level. Adding new data point every 1ms? Is this realistic desired usage?

There's absolutely no way a chart can process or even react for rejection on continuous updates every 1ms, so I can see how operations can pile up.

th3ragex commented 4 years ago

My naive assumption was to speed it up "a bit" for reproducibility. If it's caused by operations piling up then this is at least for me not relevant since it's not really a realistic scenario. I have 3x 1 to 25 values per Seconds right now.

I have debugged memory and checked my chart implementation a bit further and found something strange. There is dictionary piling up disposed LineSeriesDataItem instances:

image

The dictionary is: lineSeries.dataItemsByAxis['_dictionary']['id-105']['_dictionary']

I will try to get you a working example ASAP.

th3ragex commented 4 years ago

@martynasma: Please check: http://jsfiddle.net/e5ok8v7w/2/

I found something strange. If there is series which has no bound items the previously mentioned dictionary fills up. Once an item was added everything gets cleaned up and seems to stay in a non leaking state. (see log outputs in fiddle)

martynasma commented 4 years ago

Thanks for additional details. We are going to review this.

At this point I'm not sure when this will happen. Seems like a pretty "niche" scenario.

But will keep this open and you updated.