Prevent early deallocation of object references - #13
Merged
Conversation
Member
|
I think it should be a better approach to manage a reference count in JavaScript library #14 |
Member
Author
|
Yeah, that could work too. I wasn't sure if doing anything on the JavaScript side is slower, but most probably just incrementing and decrementing a counter is faster than maintaining a dictionary with its hashing algorithms 🙂 Also, could be more memory efficient, since you don't waste the space on the cache dictionary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently, when two references are created for the same object (i.e. with the same
id), deallocating the first references invalidates the second. This is can cause crashes, which is reproduced in the newly added test. To avoid this issue, a new privatecacheof weak references is created, which can retrieve the sameJSObjectRefinstance for the same id, when called fromRawJSValue.jsValue().Obviously, this adds some overhead on object retrieval when the Swift <-> JS bridge is crossed, but I think invalid references are a much more serious problem than this overhead. I don't know yet what implementation could be more efficient, if that's possible at all.