Memory corruption after calling methods that return SList with transfer-ownership="none" #183
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
java
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
java-gi/java-gi#183
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I've been trying to figure out what's causing memory corruption when I'm rendering text, and I think I've found it.
The finalizer registered to the
Cleanerin theSListconstructor universally callsSListNode.free(new SListNode(address));even when java-gi doesn't own the memory and shouldn't be freeing it. Examples includeLayout.getLinesReadonly()inPango.Retaining a reference to the
SListto prevent the finalizer from running does prevent the memory corruption.Thanks for the bug report. These issues a really annoying to debug. This helps a lot.
Jemalloc is really nice for finding memory leaks, but finding when and what has been preemptively been free'd is tough.
This is related, so I'm not sure if this needs to be a separate report, but there are other issues also involving returns with transfer-ownership="none".
Buffer.peekMemory()andBuffer.getMeta()in GStreamer runMemoryCleaner.takeOwnership(_instance);despite also being marked transfer-ownership="none".Buffer.peekMemory()callsg_boxed_copyto create its own copy or add a reference, and then takes ownership of the copy. The MemoryCleaner will callg_boxed_freeto free the copy (or decrease the reference). This ensures your Java variable will not be freed suddenly, while you were still using it.Similarly,
Buffer.getMeta()creates a copy of the memory of the returnedMetastruct. That memory is freed by the MemoryCleaner afterwards. (This needs more work, because the copy is "shallow":Metacontains aMetaInfochild that isn't copied.)Ah. Thanks for explaining that.
I'm still seeing some other memory issues, at least a failure to free
GdkTextures, but I'm trying to isolate that before I can confidently make a bug report. Thanks for the improvements! I'm almost back where I was with version 0.9.x without needing the explicitunref()calls.Awesome! May I ask what you are developing?