Ensure pointers indirected from Memory and pointing into Memory should retain originating object#1326
Merged
matthiasblaesing merged 2 commits intojava-native-access:masterfrom Mar 14, 2021
Conversation
0f2a5e6 to
45ceda4
Compare
Member
Author
dblock
reviewed
Mar 13, 2021
Member
|
This is A+, very nice work @matthiasblaesing. I was following the discussion out of curiosity, and thinking there has to be a better way to do this, and this is it. |
dbwiddis
reviewed
Mar 14, 2021
Contributor
dbwiddis
left a comment
There was a problem hiding this comment.
I really like this solution. A few suggestions inline.
Contributor
|
Testing: Set up an Azure VM (Windows Server 2012 R2) and created a test method exercising the current (
|
dbwiddis
reviewed
Mar 14, 2021
Member
Author
Contributor
|
LGTM! |
Member
|
Looks great, merge at will. |
…n originating object The use case is this: - native supplies the required size of a memory region - a Memory object is created with the right memory size - native fills the memory with a structure _and_ additional objects, that are held in that region, but are only referenced from the structure (one such example would be a Structure.ByReference) As long as the resulting structure stays strongly referenced from Java, all is good. When the toplevel structure goes ouf of scope, the memory backing the strucure is not strongly referenced anymore and will be freeed by GC. This change fixes the issue by ensuring, that the pointers used in substructures are SharedMemory objects, holding a strong references to the original Memory object.
83d79dd to
5d23330
Compare
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.
The use case is this:
that are held in that region, but are only referenced from the
structure (one such example would be a Structure.ByReference)
As long as the resulting structure stays strongly referenced from Java,
all is good. When the toplevel structure goes ouf of scope, the memory
backing the strucure is not strongly referenced anymore and will be
freeed by GC.
This change fixes the issue by ensuring, that the pointers used in
substructures are SharedMemory objects, holding a strong references to
the original Memory object.