fix: resolve PromiseProxy context memory leak #193
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.
This will cleanup references to
resolve
andreject
after they're called once.I'm not sure if this will solve the issue for never resolving promises, but in my tests it resolved the issues in
@nativescript/core
where ImageSource would leak after loading an image from a url.To go deeper into the issue, this happened because the promise would keep a reference to PromiseProxy's resolve/reject functions, which started to become a problem when this function would then add a native callback, which would keep a reference to the full context, keeping the resolve/reject always in memory (and usually also the promise itself).
Ultimately this created a circular reference with the
reactions_or_result
GC root that didn't go away until we removed the reference to the original resove/reject functions.Having trouble following the GC logic? Me too.
Might fix #100. Although I can't reproduce it with the repro code in that issue