Skip to content

Fix memory leak #60

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vstefanovic97
Copy link

I turns out there is a memory leak when we use Memoize in combination with tags.
For every new instance we push it's cache map to this array here, this means this array just keeps growing, event if the instance that uses that map may not be used any more (already got garbage collected)

To resolve the issue, instead of saving all these maps in an array under the tag as a key, what we do is we assign each tag a version (a unique symbol), after clear is called for a tag, we update the version of the tag.

Every time a method is called we compare it's tag version (which we save on a per instance basis), with the latest global tag version, if there is a missmatch it means we need to clear the cache for the instance, and update it's tag version with the latest.

Unfortunately this is a breaking change, as with this implementation there is no way for the clear function to return a number any more

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant