Fix memory leak when removing map #13110
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey, so I digged a little in code to resolve this issue #9126 and it kinda seems like I found what the issue is (for a bare map, nothing was touched after mounting).
Tested it using
FinalizationRegistry
and heap snapshotsBefore:
When Map was added and removed using
map.remove()
it was piling up in memory heap snapshot.After my changes:
When Map is removed and another instance of map is being mounted, previous instance is garbage collected.
Which wasn't exactly what I wanted.
I suspect that another issue lies in:
src/ui/map.js
in
_authenticate
->getMapSessionAPI
->error callback
which holds
this.painter
forever asconst mapSessionAPI_ = new MapSessionAPI();
is created in global scope and never freed.but that code is just below warning about terms of service, so I'm not touching that :p
For future issues: Do I have permission to modify/debug this code with good intentions? All changes that improve mapbox would be put out in public PRs to approve by mapbox team.
@mourner @stepankuzmin let me know if that works and if you could handle issue in code that is under TOS 馃