-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leaking of Observable Maps (), because _hasMap keeps links on all once used keys (key could be object) and never delete them #2031
Comments
I wonder if WeakMap could be helpful here. |
@FredyC |
+++ So the |
Yea, I have no idea why is it implemented like that. Hopefully, @mweststrate can stop by and shed some light onto this. |
We can remove unobserved atoms from this map. We don't need them. |
IIRC there is no specific reason for it being implemented this way, than mere legacy. Up to MobX 4 only primitives were supported as map keys, so the problem (barely) existed in that scenario. A PR that cleans up unobserved entries as suggestd by @mayorovp in the |
@mweststrate what about my PR? |
Apologies, overlooked that! |
Released as 4.13.0 / 5.13.0 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions. |
Issue:
I find that observable Maps absolutely always loose a memory. For every key of the map, you create same key in your private map called _hasMap and place there a boolean value. But these keys are kept there even the origin map is empty or already doesn't contain the key. Don't forget that key could be large object or linked with many other objects. So we loose all memory even we don't keep links (have variables) to these key object in our code, because the _hasMap keeps links on all once used keys (key - is the big object, remember ?) and never delete them.
Please see the example:
https://codesandbox.io/s/minimal-mobx-react-project-1uyb0
Of cause we expected that we don't see the our objects in memory heap, after clearing the map.
Idea:
You should use another mechanism to register of using the map methods and of getting values.
The text was updated successfully, but these errors were encountered: