-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure pointers indirected from Memory and pointing into Memory should retain originating object #1326
Ensure pointers indirected from Memory and pointing into Memory should retain originating object #1326
Conversation
0f2a5e6
to
45ceda4
Compare
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this solution. A few suggestions inline.
Testing: Set up an Azure VM (Windows Server 2012 R2) and created a test method exercising the current (
|
LGTM! |
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
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.