Skip to content
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

Rework memory management #29

Merged
merged 8 commits into from
Jan 9, 2023
Merged

Rework memory management #29

merged 8 commits into from
Jan 9, 2023

Conversation

jwharm
Copy link
Owner

@jwharm jwharm commented Jan 9, 2023

This PR refactors a number of fundamental flaws in java-gi:

  • Ownership handling does not belong in the proxy object constructor. It is now handled with explicit takeOwnership and yieldOwnership calls as specified in the GIR files.
  • Split the Cleaner from ObjectBase into its own class
  • Fixed ownership of callback return values: this is exactly opposite of regular methods
  • Implemented much improved handling of allocated memory segments. All generated code that allocates memory is now wrapped in a try-with-resources statement to automatically release the memory afterwards. The only exception is the allocation of upcalll stubs: These are allocated in the global scope, and therefore never released.
  • The memory allocation lifetimes introduced an extra indentation level, on top of the existing ones. This has been refactored so indentation is now inserted automatically after every newline. The indentation level is increased and decreased where necessary during code generation.
  • Small fix for Union types. These inherited from ObjectBase but they are more akin to structs.

@jwharm
Copy link
Owner Author

jwharm commented Jan 9, 2023

The fix for ownership handling of callback return values also resolved the issue that I encountered in #20 .

@jwharm jwharm merged commit 01d1a7b into main Jan 9, 2023
@jwharm jwharm deleted the rework-memory-management branch January 9, 2023 22:06
@jwharm jwharm mentioned this pull request Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant