-
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
Rework handle ownership #2795
Rework handle ownership #2795
Conversation
Pull Request Test Coverage Report for Build 1776006405
💛 - Coveralls |
@@ -25,7 +25,7 @@ | |||
|
|||
namespace Realms | |||
{ | |||
internal class MongoCollectionHandle : RealmHandle | |||
internal class MongoCollectionHandle : StandaloneHandle |
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.
I didn't know about this part of the code. Is it a small subset duplicating what the c# driver does?
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.
It's nowhere near as comprehensive as the driver - the server exposes a REST-like API to query MongoDb and we're wrapping that here. But we're not querying MongoDb directly.
Realm/Realm/Handles/ObjectHandle.cs
Outdated
@@ -98,19 +98,26 @@ public bool IsValid | |||
{ | |||
get | |||
{ | |||
if (IsClosed) |
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.
We don't check for the root here?
* main: Add notifications_cs.hpp to cmake lists Strip [UsedImplicitly] from the Remotion assembly (#2810) Allow setting primary keys during migration (#2793) fix typo (#2804) Remove various master references + fix up some stale docs (#2791) Rework handle ownership (#2795) Bump SharpZipLib from 1.3.2 to 1.3.3 in /Tools/SetupUnityPackage (#2798) Add a migration test that removes objects from the Realm (#2792)
Description
This is a major change that reshuffles the handle hierarchy quite a bit. It's very much a WIP, but would appreciate any early feedback.
StandaloneHandle
) - e.g.User
,App
,ThreadSafeReference
- those are types that exist on their own and have no ownership semantics with other types. Those are also typically not disposable.RealmHandle
) - e.g.Object
,RealmList
,Results
, etc. - those types are owned by aRealm
instance and their lifetime is bound to that instance.SharedRealmHandle
) - this is a standalone type, but it takes care of unbinding its child handles at opportune times.UnownedRealmHandle
- this is a subtype ofSharedRealmHandle
that doesn't delete its native pointer because it wasn't the SDK that created it. Additionally, it keeps a weak list of all its children and closes them as soon as it gets closed. This is used in migrations, where we don't want to have objects outliving the Realm instance as this may keep the native instance alive and cause all sorts of issues.Discussion items:
EnsureValid()
on every handle method. It's easy to forget and if we do, attempting to call the method will throw a vagueObjectDisposedException
. I tried a bunch of clever approaches, but wasn't happy with any of them. Open for smart ideas.TODO