Skip to content
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

Fix Finalizer_A01_t04.dart test #3020

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> completer = Completer<void>();

@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);
Expand Down
3 changes: 1 addition & 2 deletions LanguageFeatures/FinalizationRegistry/gc_utils_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading