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

tp_dealloc & threads #526

Open
ronaldoussoren opened this issue Jan 18, 2023 · 1 comment
Open

tp_dealloc & threads #526

ronaldoussoren opened this issue Jan 18, 2023 · 1 comment

Comments

@ronaldoussoren
Copy link
Owner

ronaldoussoren commented Jan 18, 2023

There is no guarantee as to which thread is used to deallocate an object. Especially with cycles deallocation could happen on a second thread that happens to break the reference cycle by running the GC.

This can be a problem if "MainActor" proxy objects happen to be deallocated on a secondary thread and Python's reference is the last one that keeps the ObjC object alive.

In practice I haven't run into this problem yet. I've created this issue to ensure I don't forget to look into this in the future. It might be possible to arrange for calls to -release in the deallocation of proxy objects to happen on the main thread or the thread that created the proxy object. This needs to be designed and verified to make sure this doesn't holes were ObjC objects can be reallocated on the wrong thread (for example through autorelease pools)

Also research if there are frameworks that require handling objects on specific threads other than the main thread. One possible example is CoreData, AFAIK that framework can be used on multiple threads, but does require per-thread contexts.

Open question: what to do if the thread that created the proxy no longer exists when the proxy needs to release its reference tot the Objective-C object.

@ronaldoussoren
Copy link
Owner Author

Any implementation work this needs thorough testing, both to show the problem in the current implementation and to show that the changed implementation actually fixes the issue.

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

No branches or pull requests

1 participant