blob: af1f22e2cc2a199496d81e1952a6cf84346a3209 [file] [log] [blame]
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// @assertion If a non-null detach value is provided, that object can be passed
/// to Finalizer.detach to remove the attachment again.
/// @description Checks that if detach token was passed to [attach], given
/// object can be detached from the finalizer using [detach].
/// @author
import '../../gc_utils_lib.dart';
import '../../../../Utils/expect.dart';
class A {}
int called = 0;
final Finalizer finalizer = Finalizer((_) {
Object test1(Object obj) => obj;
main() async {
Object value = Object();
Object detachToken = A();
finalizer.attach(value, "Finalization token", detach: detachToken);
value = 12345;
// Initial object is not accessible anymore.
// Do something, call triggerGC several times and check that callback was
// not called during the execution.
await triggerGcWithDelay();
var value1 = test1(value);
await triggerGcWithDelay();
Expect.equals(0, called);