blob: 489419c658508c7e0a7b7a59881abd0957bfe697 [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 target property
/// T? target
/// The current object weakly referenced by this, if any.
///
/// The value is either the object supplied in the constructor, or null if the
/// weak reference has been cleared.
///
/// @description Check that the value of this property value is either the
/// object supplied in the constructor, or null if the weak reference has been
/// cleared
/// @author sgrekhov@unipro.ru
/// @issue 48391
import "../../gc_utils_lib.dart";
import "../../../../Utils/expect.dart";
class C {
int id;
C(this.id);
String toString() => "C($id)";
}
@pragma('vm:never-inline')
WeakReference<C> createWeakReference() {
List<C> refs = List.filled(5, C(42), growable: true);
WeakReference<C> wr = WeakReference(refs[0]);
Expect.equals(refs[0], wr.target);
triggerGc();
Expect.equals(refs[1], wr.target);
return wr;
}
main() {
WeakReference<C> wr = createWeakReference();
triggerGc();
Expect.isNull(wr.target);
}