Skip to content

Ensure end-of-application object lifecycle is clean - #82

Open
freakboy3742 wants to merge 1 commit into
mainfrom
finalize-cleanup
Open

Ensure end-of-application object lifecycle is clean#82
freakboy3742 wants to merge 1 commit into
mainfrom
finalize-cleanup

Conversation

@freakboy3742

Copy link
Copy Markdown
Member

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.

Refs beeware/briefcase-macOS-Xcode-template#134. It's much less of an issue on iOS because an app doesn't ever really "exit", but to ensure we're catching the edge case of a crash on actual app exit, it's worth maintaining parity.

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

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