Chromium Code Reviews| Index: tests/language/closure_cycles_test.dart |
| =================================================================== |
| --- tests/language/closure_cycles_test.dart (revision 0) |
| +++ tests/language/closure_cycles_test.dart (revision 0) |
| @@ -0,0 +1,39 @@ |
| +// 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. |
| + |
| +import "dart:async"; |
|
regis
2013/01/07 22:10:18
I think you need a library statement for Dartium t
Ivan Posva
2013/01/08 17:37:38
Done.
|
| + |
| +class X { |
| + Function onX; |
| + X() { new Timer(0, (_) => 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); |
| + // Termintate the test if we allocated enough memory without running out. |
|
regis
2013/01/07 22:10:18
Terminate
Ivan Posva
2013/01/08 17:37:38
Done.
|
| + if (count++ > 100) return; |
| + new Timer(0, (_) => onY()); |
| + } |
| +} |
| + |
| +void doIt() { |
| + var x = new X(); |
| + x.onX = (y) { |
| + y.onY = () { |
| + y; // Remove this line to avoid memory leak! |
| + doIt(); |
| + }; |
| + }; |
| +} |
| + |
| +void main() { |
| + doIt(); |
| +} |