Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Side by Side Diff: tests/language/closure_cycles_test.dart

Issue 12213092: Rework Timer interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/isolate/timer_test.dart ('k') | tests/lib/async/future_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 // Based on dartbug.com/7681 4 // Based on dartbug.com/7681
5 // Verify that context chains do not lead to unintended memory being held. 5 // Verify that context chains do not lead to unintended memory being held.
6 6
7 library closure_cycles_test; 7 library closure_cycles_test;
8 8
9 import "dart:async"; 9 import "dart:async";
10 10
11 class X { 11 class X {
12 Function onX; 12 Function onX;
13 X() { new Timer(0, (_) => onX(new Y())); } 13 X() { Timer.run(() => onX(new Y())); }
14 } 14 }
15 15
16 class Y { 16 class Y {
17 Function onY; 17 Function onY;
18 var heavyMemory; 18 var heavyMemory;
19 static var count = 0; 19 static var count = 0;
20 Y() { 20 Y() {
21 // Consume large amounts of memory per iteration to fail/succeed quicker. 21 // Consume large amounts of memory per iteration to fail/succeed quicker.
22 heavyMemory = new List(10*1024*1024); 22 heavyMemory = new List(10*1024*1024);
23 // Terminate the test if we allocated enough memory without running out. 23 // Terminate the test if we allocated enough memory without running out.
24 if (count++ > 100) return; 24 if (count++ > 100) return;
25 new Timer(0, (_) => onY()); 25 Timer.run(() => onY());
26 } 26 }
27 } 27 }
28 28
29 void doIt() { 29 void doIt() {
30 var x = new X(); 30 var x = new X();
31 x.onX = (y) { 31 x.onX = (y) {
32 y.onY = () { 32 y.onY = () {
33 y; // Capturing y can lead to endless context chains! 33 y; // Capturing y can lead to endless context chains!
34 doIt(); 34 doIt();
35 }; 35 };
36 }; 36 };
37 } 37 }
38 38
39 void main() { 39 void main() {
40 doIt(); 40 doIt();
41 } 41 }
OLDNEW
« no previous file with comments | « tests/isolate/timer_test.dart ('k') | tests/lib/async/future_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698