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

Unified Diff: tests/language/closure_cycles_test.dart

Issue 11798004: - Add a test for context cycles. Based on dartbug.com/7681. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,41 @@
+// 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() { 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);
+ // Terminate the test if we allocated enough memory without running out.
+ if (count++ > 100) return;
+ new Timer(0, (_) => 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();
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698