highslide-software/highcharts.com — Issue #526: Memory leak on chart.destroy()
Author: josephruscio
Created: 2011-10-25 23:58:31+00:00
State: open

When we first started using the Highstock beta the [`addPoint()` implementation was broken](http://highslide.com/forum/viewtopic.php?f=12&t=11527&p=51721#p51721). So in order to implement dynamically updating charts, we instead had to on each interval construct a whole new chart with the new series data. When new data arrives we:

1. Add the new data to the end of our cached data array.
1. Shift the same number of datapoints off the front of the cached data array
1. Call `chart.destroy()` on the current chart
1. Assign `chart = new Highcharts.StockChart(options)`

Even though we call `destroy()` and re-assign the existing chart reference to the new object, we're still seeing a big memory leak. I've coded up a [reference implementation of our current design in jsfiddle](http://jsfiddle.net/YD6tE/), if you watch memory in Chrome Task Manager you will see it climb over time. When I implement the same dynamic data behavior using the now working `addPoint()` implementation. I see no leaks.

We're going to switch to `addPoint()` as it simplifies our code anyways, but you'll probably want to figure this out for use-cases that do involve creating/destroying a lot of charts on one page.