blob: 68a2d78e9a8d21e5d8bb8909cfd48f5ded1ced84 [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
import "../gc_utils_lib.dart";
import "../../../Utils/expect.dart";
class C {
int id;
C(this.id);
}
C? c = C(42);
main() {
WeakReference<C> wr = WeakReference(c!);
Expect.equals(c, wr.target);
triggerGc();
Expect.equals(c, wr.target);
c = null;
triggerGc();
Expect.isNull(wr.target);
}