mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 23:31:42 +00:00
3803057169
./language[_strong]/class_keyword_test.dart
./language[_strong]/closure_shared_state_test.dart
R=johnniwinther@google.com
NOTE: I had to bypass hooks since the analyser fails on the files that have static compile-time errors. Should I do something else?
Committed: fa59030f18
Review-Url: https://codereview.chromium.org/3001433002 .
44 lines
974 B
Dart
44 lines
974 B
Dart
// Copyright (c) 2011, 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.
|
|
// Based on dartbug.com/7681
|
|
// Verify that context chains do not lead to unintended memory being held.
|
|
|
|
library closure_cycles_test;
|
|
|
|
import "dart:async";
|
|
|
|
class X {
|
|
Function onX;
|
|
X() {
|
|
Timer.run(() => onX(new Y()));
|
|
}
|
|
}
|
|
|
|
class Y {
|
|
Function onY;
|
|
var heavyMemory;
|
|
static var count = 0;
|
|
Y() {
|
|
// Consume large amounts of memory per iteration to fail/succeed quicker.
|
|
heavyMemory = new List(10 * 1024 * 1024);
|
|
// Terminate the test if we allocated enough memory without running out.
|
|
if (count++ > 100) return;
|
|
Timer.run(() => onY());
|
|
}
|
|
}
|
|
|
|
void doIt() {
|
|
var x = new X();
|
|
x.onX = (y) {
|
|
y.onY = () {
|
|
y; // Capturing y can lead to endless context chains!
|
|
doIt();
|
|
};
|
|
};
|
|
}
|
|
|
|
void main() {
|
|
doIt();
|
|
}
|