-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
Description
The following example (from cl/363581):
Future testWeakReferenceWeakness() async {
late final WeakReference<Foo> weakReference;
{
Foo? foo = Foo();
weakReference = WeakReference<Foo>(foo);
Expect.equals(weakReference.target, foo);
foo = null;
}
asyncStart();
while (weakReference.target != null) {
produceGarbage();
await Future.delayed(const Duration(milliseconds: 10));
}
Expect.isNull(weakReference.target);
asyncEnd();
}is allocating an object that becomes immediately unreachable. We then produce garbage until the object was collected and the weak reference to it null'ed out.
This works in JIT mode but in AOT it seems that the optimizer is going to optimize it (incorrectly IMHO) away by forwarding the allocated object to the load from the WeakReference.
This is proof that the optimizer can prevent collection of unreachable objects.
/cc @alexmarkov @mraleph opinions on this behavior?
Metadata
Metadata
Assignees
Labels
area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.