Fix Rust values getting GC'd while still borrowed and not getting GC'd if created via. constructor #3940
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.
Fixes #3854.
Supersedes #3743.
This implements the alternative reference-counting based fix that I proposed in #3743.
I also added some tests for it. It turns out there was already an existing test around GC, which meant that Node's
--expose-gc
flag was already enabled for manually triggering garbage collection.I ended up merging it together with my tests, and then running them sequentially since attempting to run multiple GCs in parallel seemed to make it flaky. It was still somewhat flaky after that point, though: the garbage collector just decided not to clean up the
OwnedValue
s sometimes. For whatever reason, 'warming it up' by just running a bunch of pointless GCs before the tests seems to fix it; I might try and investigate why at some point, but for now it works.