-
Type: Bug
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
2 - S (<= 1 week)
-
2616
This can be demonstrated with this sample code
myrealm.MyCustomValue = getValue();
myrealm.addListener("change", (realm, notification) => {
console.log(myrealm == realm); //false
console.log(realm.MyCustomValue != undefined); //false
})
the realm instance inside the callback is a newly created realm instance just before invoking the callback. This is not only inefficient but also brakes logic and expectations as the above sample.
A better way would be to create a partially bound function which has the same myrealm instance as the first argument then preserve this bound function so notifications can be raised.
The creation of newly created realm just before invoking the callback happen here
Care should be taken not to create cycle retention of realm instances. ie the GC should be able to free the realm instance in any time.