diff --git a/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/Finalizer_A01_t04.dart b/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/Finalizer_A01_t04.dart index f8aecaea93..ab127a5507 100644 --- a/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/Finalizer_A01_t04.dart +++ b/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/Finalizer_A01_t04.dart @@ -13,34 +13,39 @@ /// will never run if attached object is accessible. /// @author iarkh@unipro.ru +import 'dart:async'; import '../../gc_utils_lib.dart'; import '../../../../Utils/expect.dart'; int called = 0; - +Object? accessibleLink; final Finalizer finalizer = Finalizer((token) { Expect.equals(123, token); called++; }); +Completer completer = Completer(); + @pragma('vm:never-inline') attachToFinalizer() async { - Object? liveObject; - Object object = Object(); + Object? object = Object(); finalizer.attach(object, 123); await triggerGcWithDelay(); + accessibleLink = object; + object = null; Expect.equals(0, called); - liveObject = object; () async { await triggerGcWithDelay(); Expect.equals(0, called); + completer.complete(); }(); - print(liveObject); } main() async { await attachToFinalizer(); + await completer.future; + accessibleLink = null; // Previous triggerGc move some objects to old space. Do multiple GCs to // force all objects to old space. await triggerGcWithDelay(repeat: 3); diff --git a/LanguageFeatures/FinalizationRegistry/gc_utils_lib.dart b/LanguageFeatures/FinalizationRegistry/gc_utils_lib.dart index bec9521ef1..28da49fa9f 100644 --- a/LanguageFeatures/FinalizationRegistry/gc_utils_lib.dart +++ b/LanguageFeatures/FinalizationRegistry/gc_utils_lib.dart @@ -2,8 +2,7 @@ // 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. -/// @description Check that WeakReference constructor rejects any object that is -/// not supported as an Expando key. Test Strings. +/// @description Library for work with Dart garbage collector tools. /// @author sgrekhov@unipro.ru library gc_utils_lib;