-
Notifications
You must be signed in to change notification settings - Fork 167
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
Clean up native resources on Unity application exit #2467
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Realm/Realm/Handles/AppHandle.cs
Outdated
{ | ||
foreach (var weakHandle in _appHandles) | ||
{ | ||
if (weakHandle.Target is AppHandle handle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we only being overly cautious here with the is operator and then then the null conditional operator? It seems it can't be anything else than AppHandle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beside the part that Ferdinando pointed out, the solution looks good. Most importantly, good stuff in discovering something that looks tedious to figure out.
541e285
to
e2ba2f0
Compare
45050cd
to
518fbcd
Compare
* master: Update the AppConfiguration.Logger obsolete message (#2495) Add more serializer types to the preserved ones (#2489) Update changelog from Core (#2488) Build an xcframework for iOS (#2475) Prepare for vNext (#2487) Prepare for 10.2.1 (#2484) Fix TableKey / ObjKey conversion on Android x86 (#2477) Update the build manager locations (#2474) Clean up native resources on Unity application exit (#2467) Fix some native warnings (#2483) Don't try to get the app from a removed user (#2480) Use delete_files from core when deleting a Realm. (#2401) Fixes for the sync datatype tests (#2461) Clean up the package.json and add some docs (#2452) Run iOS tests on CI (#2405) Verify that objects do not belong to different realm when added to collection (#2465) Updated README instructions (#2459)
Description
When Unity closes the application, it will suspend garbage collection and wait for all native threads to exit (or at least stop doing work - threads that are waiting on conditional variables are not an issue). This is problematic because the managed AppHandle holds a shared_ptr to the native App, which in turn holds a shared_ptr to the SyncManger. This prevents the destruction of the SyncManager and this is where we actually stop the sync client. Not stopping the sync client means that it'll keep polling the socket in a loop, forcing Unity to wait forever.
The fix is to keep a collection of weak references to each AppHandle we create and force close all of them when the application exits.
TODO