Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // Based on dartbug.com/7681 | |
| 5 // Verify that context chains do not lead to unintended memory being held. | |
| 6 | |
| 7 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.
| |
| 8 | |
| 9 class X { | |
| 10 Function onX; | |
| 11 X() { new Timer(0, (_) => onX(new Y())); } | |
| 12 } | |
| 13 | |
| 14 class Y { | |
| 15 Function onY; | |
| 16 var heavyMemory; | |
| 17 static var count = 0; | |
| 18 Y() { | |
| 19 // Consume large amounts of memory per iteration to fail/succeed quicker. | |
| 20 heavyMemory = new List(10*1024*1024); | |
| 21 // 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.
| |
| 22 if (count++ > 100) return; | |
| 23 new Timer(0, (_) => onY()); | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 void doIt() { | |
| 28 var x = new X(); | |
| 29 x.onX = (y) { | |
| 30 y.onY = () { | |
| 31 y; // Remove this line to avoid memory leak! | |
| 32 doIt(); | |
| 33 }; | |
| 34 }; | |
| 35 } | |
| 36 | |
| 37 void main() { | |
| 38 doIt(); | |
| 39 } | |
| OLD | NEW |