highslide-software/highcharts.com — pull request #3485 by sfishel18 (2014-10-03 01:28:42+00:00)
Title: Fix for document mouseup/touchend listener leak

When a chart is drawn into a container that already contains a chart, the previous chart is destroyed but it's mouseup/touched listeners are not unbound. The problem seems to be that things happen in this order:

1) The new chart is added to the global list in `Chart#init`, `chartCount` becomes 2.
2) The old chart is destroyed in `Chart#getContainer` removing it from the global list, `chartCount` becomes 1.
3) The old chart's pointer is then destroyed, `chartCount` is 1 so it does not remove its mouseup/touchend listeners.
4) The new chart's pointer is created in `Chart#firstRender`, `chartCount` is 1 so it attaches new mouseup/touchend listeners.

A demo of the issue can be found here: http://jsfiddle.net/sfishel_splunk/LLExL/3452/

My proposed fix is to move the incrementing/decrementing logic for counter into the `Pointer` object so that transactional integrity is maintained.