Skip to content
Merged
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 @@ -10,15 +10,15 @@
/// and will run in that zone when called.
///
/// @description Checks that finalizer object can be created and its callback
/// will never run if attached object is accessible.
/// will never run if attached object is accessed.
/// @author iarkh@unipro.ru

import 'dart:async';
import '../../gc_utils_lib.dart';
import '../../../../Utils/expect.dart';

int called = 0;
Object? accessibleLink;
Object? accessedLink;

final Finalizer finalizer = Finalizer((token) {
Expect.equals(123, token);
Expand All @@ -32,20 +32,23 @@ attachToFinalizer() async {
Object? object = Object();
finalizer.attach(object, 123);
await triggerGcWithDelay();
accessibleLink = object;
accessedLink = object;
object = null;
Expect.equals(0, called);
() async {
await triggerGcWithDelay();
Expect.equals(0, called);
// If accessedLink is never read the optimizer may kill the object after
// `object = null`. Read it here to avoid it.
print(accessedLink);
completer.complete();
}();
}

main() async {
await attachToFinalizer();
await completer.future;
accessibleLink = null;
accessedLink = 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
Loading