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

Improve memory management documentation #48

Open
dimaqq opened this issue Jul 8, 2017 · 3 comments · May be fixed by #543
Open

Improve memory management documentation #48

dimaqq opened this issue Jul 8, 2017 · 3 comments · May be fixed by #543
Labels
documentation An improvement required in the project's documentation. enhancement New features, or improvements to existing features.

Comments

@dimaqq
Copy link

dimaqq commented Jul 8, 2017

Looking at old SO discussion (e.g. https://stackoverflow.com/a/6610/705086 ) it looks like when SomeOBJCClass.alloc().init() is called from Python code, it becomes Python's responsibility either to .release() the resulting object on the spot, or to mark it for GC at the bottom of event loop using .autorelease().

Is that correct?

If that's correct, it must be documented...

@dimaqq
Copy link
Author

dimaqq commented Jul 8, 2017

Actually reading up on ARC, I'm completely confused... are calls to .alloc() recorded to current autorelease pool by the compiler or runtime?

Depending on that, Python must or must not call .[auto]release()...

@dgelessus
Copy link
Collaborator

ARC is a compiler feature, it makes the compiler insert retain/release calls so the programmer doesn't have to. Because rubicon-objc operates at the runtime level, there is no way to use ARC. That means you have to insert retain/release/autorelease calls in the correct places, like you would without ARC.

Alternatively, it would be possible to make rubicon-objc call retain and release automatically. This is how Pythonista's objc_util module does it - it calls retain when an ObjCInstance is created, and release when it is garbage-collected (in __del__). The only issue with this is that it needs special cases for alloc/copy/mutableCopy/new methods, which return an already retained object (docs).

@freakboy3742 freakboy3742 added enhancement New features, or improvements to existing features. up-for-grabs labels Apr 25, 2020
@freakboy3742 freakboy3742 added the documentation An improvement required in the project's documentation. label Apr 13, 2023
@mhsmith mhsmith changed the title Document autorelease Improve memory management documentation Apr 16, 2024
@mhsmith
Copy link
Member

mhsmith commented Apr 16, 2024

it would be possible to make rubicon-objc call retain and release automatically. This is how Pythonista's objc_util module does it - it calls retain when an ObjCInstance is created, and release when it is garbage-collected (in __del__

This was implemented in #201, but the documentation is still lacking:

  • rubicon-objc-api says "Rubicon currently does not perform any automatic memory management on the Objective-C object wrapped in an ObjCInstance", which is no longer true.
  • memory-management says "You won’t have to manage reference counts in Python, Rubicon Objective-C will do that work for you." This is over-optimistic, as is shown by the various manual retain/release calls in Toga, and the discussion in Improve correspondence between ObjectiveC objects and Python wrappers #256.
  • The fact that calling release or autorelease disables the automatic release in __del__ is mentioned in those methods' docstrings, but those strings aren't included in the HTML documentation.

@mhsmith mhsmith linked a pull request Nov 24, 2024 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation An improvement required in the project's documentation. enhancement New features, or improvements to existing features.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants