Fix multiple memory leaks in UserCountryMap #11350
See commits for details. The Raphael upgrade fixes the most serious memory leak.
You can verify the problem(s) by following these steps.
Prerequisites: The map is visible on the dashboard (i.e., piwik has collected data recently)
In addition, every time you click on the "Dashboard" link in the left menu, Piwik appends a
Without this change, it is very easy for an application to slowly leak memory as Raphael continues to add new keys to `eldata`. This memory leak turns out to be a problem for [Piwik](https://piwik.org/), which uses kartographer.js (which uses raphael) to draw an SVG image of the United States in its analytics dashboard ([see demo](https://demo.piwik.org/index.php?module=CoreHome&action=index&idSite=3&period=day&date=yesterday)). Every time the dashboard is redrawn, it spawns ~700 new Elements with data. [I've submitted a pull request that appropriately cleans up this data when the user navigates away from the page using `removeData`](matomo-org/matomo#11350), but Raphael leaves an empty object in the `eldata` map keyed on the element's old ID. Since kartographer/Piwik does not reuse IDs, `eldata` will grow continually on each redraw until the application is out of memory.
Note that there is still a tiny small memory leak caused by Raphael's behavior. I've submitted a PR to Raphael that eliminates this tiny memory leak.
Regardless, this PR alone turns the large memory leak into a tiny memory leak, so it is worth considering / merging before Raphael considers/merges the other fix.
The previous version of the code inappropriately tried to remove the event listener; the `function` object for `onResizeLazy` is different across maps.
@jvilk thanks for that PR. Seems to fix the memory leak in this case.
I'm gonna merge this now.
While testing I maybe found another memory leak. When clicking the reload button for the usercountry widget the required memory still increases a lot, guess the widget is not destroyed before it's reloaded or something similar. Would you maybe be keen to have a look at that, too?