[x] I'm sure this is a Leaflet.MarkerCluster code issue, not an issue with my own code nor with the framework I'm using (Cordova, Ionic, Angular, React…)
[x] I've searched through the issues to make sure it's not yet reported
What behaviour I'm expecting and which behaviour I'm seeing
I'm not expecting a memory leak but I'm seeing one
When markers are added or removed the grid inside DistanceGrid is updated.
When objects are added to the grid, entries are created in those dictionaries and the object is inserted into the appropriate place in the final array. When objects are removed from the grid, the object is removed from the row, and the row is removed, but the top-level part of the grid isn't removed.
So if we start with an empty grid and add an object O at
How to reproduce
What behaviour I'm expecting and which behaviour I'm seeing
I'm not expecting a memory leak but I'm seeing one
When markers are added or removed the grid inside DistanceGrid is updated.
When objects are added to the grid, entries are created in those dictionaries and the object is inserted into the appropriate place in the final array. When objects are removed from the grid, the object is removed from the row, and the row is removed, but the top-level part of the grid isn't removed.
So if we start with an empty grid and add an object O at
{x: 1, y: 2} , the grid becomes grid: { '2': { '1': [O] } }
When that object is removed, the grid becomes: grid: { '2': {} }
It doesn't remove the row object when empty, however. It would be worth considering modifying the code to add:
if (Object.keys(row).length === 0) { delete grid[y]; }
just after the
delete row[x];
line.
If we insert objects at 1 million different y positions, that grid object will accumulate 1 million empty objects and never clean them up.