Skip to content

Ensure end-of-application object lifecycle is clean. - #135

Merged
freakboy3742 merged 1 commit into
mainfrom
finalize-cleanup
Sep 3, 2026
Merged

Ensure end-of-application object lifecycle is clean.#135
freakboy3742 merged 1 commit into
mainfrom
finalize-cleanup

Conversation

@freakboy3742

Copy link
Copy Markdown
Member

Fixes #134.

If a Toga object is created, but not added to a layout, it creates a number of cyclic object references. When the application exits, these references are garbage collected. Rubicon deallocates those objects by marking them for autorelease, with a closure (through WrappedPyObject) to ensure that the Python object is also dropped.

When the autorelease pool exits, any object that is referenced by Python will be cleaned up via the closure - but the current code invokes Py_Finalize() inside the autorelease pool, so the Python interpreter has already shut down when the final ObjC objects are released. This causes a segfault because a non-existent Python interpreter is used in deallocation calls.

PR Checklist:

  • I will abide by the BeeWare Code of Conduct
  • I have read and have followed the CONTRIBUTING.md file
  • This PR was generated or assisted using an AI tool
    Assisted-by: Claude Opus 5

@freakboy3742
freakboy3742 merged commit 77c07b5 into main Sep 3, 2026
20 checks passed
@freakboy3742
freakboy3742 deleted the finalize-cleanup branch September 3, 2026 05:35
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.

Segfault after application exit with dangling ObjC objects

2 participants