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

Side by Side Diff: runtime/observatory/lib/src/app/view_model.dart

Issue 973553005: Fix memory leak in CPU Profile page (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 4
5 part of app; 5 part of app;
6 6
7 abstract class TableTreeRow extends Observable { 7 abstract class TableTreeRow extends Observable {
8 static const arrowRight = '\u2192'; 8 static const arrowRight = '\u2192';
9 static const arrowDownRight = '\u21b3'; 9 static const arrowDownRight = '\u21b3';
10 // Number of ems each subtree is indented. 10 // Number of ems each subtree is indented.
11 static const subtreeIndent = 2; 11 static const subtreeIndent = 2;
12 12
13 TableTreeRow(this.tree, TableTreeRow parent) : 13 TableTreeRow(this.tree, TableTreeRow parent) :
14 parent = parent, 14 parent = parent,
15 depth = parent != null ? parent.depth + 1 : 0 { 15 depth = parent != null ? parent.depth + 1 : 0 {
16 } 16 }
17 17
18 final TableTree tree; 18 final TableTree tree;
19 final TableTreeRow parent; 19 final TableTreeRow parent;
20 final int depth; 20 final int depth;
21 final List<TableTreeRow> children = new List<TableTreeRow>(); 21 final List<TableTreeRow> children = new List<TableTreeRow>();
22 final List<TableCellElement> _tableColumns = new List<TableCellElement>(); 22 final List<TableCellElement> _tableColumns = new List<TableCellElement>();
23 final List<DivElement> flexColumns = new List<DivElement>(); 23 final List<DivElement> flexColumns = new List<DivElement>();
24 final List<StreamSubscription> listeners = new List<StreamSubscription>();
25
24 SpanElement _expander; 26 SpanElement _expander;
25 TableRowElement _tr; 27 TableRowElement _tr;
26 TableRowElement get tr => _tr; 28 TableRowElement get tr => _tr;
27 bool _expanded = false; 29 bool _expanded = false;
28 bool get expanded => _expanded; 30 bool get expanded => _expanded;
29 set expanded(bool expanded) { 31 set expanded(bool expanded) {
30 var changed = _expanded != expanded; 32 var changed = _expanded != expanded;
31 _expanded = expanded; 33 _expanded = expanded;
32 if (changed) { 34 if (changed) {
33 // If the state has changed, fire callbacks. 35 // If the state has changed, fire callbacks.
(...skipping 26 matching lines...) Expand all
60 HtmlElement _makeColorBlock(String backgroundColor) { 62 HtmlElement _makeColorBlock(String backgroundColor) {
61 var colorBlock = new DivElement(); 63 var colorBlock = new DivElement();
62 colorBlock.style.minWidth = '2px'; 64 colorBlock.style.minWidth = '2px';
63 colorBlock.style.backgroundColor = backgroundColor; 65 colorBlock.style.backgroundColor = backgroundColor;
64 return colorBlock; 66 return colorBlock;
65 } 67 }
66 68
67 HtmlElement _makeExpander() { 69 HtmlElement _makeExpander() {
68 var expander = new SpanElement(); 70 var expander = new SpanElement();
69 expander.style.minWidth = '1.5em'; 71 expander.style.minWidth = '1.5em';
70 expander.onClick.listen(onClick); 72 listeners.add(expander.onClick.listen(onClick));
71 return expander; 73 return expander;
72 } 74 }
73 75
76 void _cleanUpListeners() {
77 for (var i = 0; i < listeners.length; i++) {
78 listeners[i].cancel();
79 }
80 listeners.clear();
81 }
82
74 void onClick(Event e) { 83 void onClick(Event e) {
75 e.stopPropagation(); 84 e.stopPropagation();
76 tree.toggle(this); 85 tree.toggle(this);
77 } 86 }
78 87
79 static const redColor = '#F44336'; 88 static const redColor = '#F44336';
80 static const blueColor = '#3F51B5'; 89 static const blueColor = '#3F51B5';
81 static const purpleColor = '#673AB7'; 90 static const purpleColor = '#673AB7';
82 static const greenColor = '#4CAF50'; 91 static const greenColor = '#4CAF50';
83 static const orangeColor = '#FF9800'; 92 static const orangeColor = '#FF9800';
(...skipping 21 matching lines...) Expand all
105 var backgroundColor = lightGrayColor; 114 var backgroundColor = lightGrayColor;
106 if (depth > 1) { 115 if (depth > 1) {
107 var colorIndex = (depth - 1) % backgroundColors.length; 116 var colorIndex = (depth - 1) % backgroundColors.length;
108 backgroundColor = backgroundColors[colorIndex]; 117 backgroundColor = backgroundColors[colorIndex];
109 } 118 }
110 var colorBlock = _makeColorBlock(backgroundColor); 119 var colorBlock = _makeColorBlock(backgroundColor);
111 firstColumn.children.add(colorBlock); 120 firstColumn.children.add(colorBlock);
112 _expander = _makeExpander(); 121 _expander = _makeExpander();
113 firstColumn.children.add(_expander); 122 firstColumn.children.add(_expander);
114 // Enable expansion by clicking anywhere on the first column. 123 // Enable expansion by clicking anywhere on the first column.
115 firstColumn.onClick.listen(onClick); 124 listeners.add(firstColumn.onClick.listen(onClick));
116 _updateExpanderView(); 125 _updateExpanderView();
117 } 126 }
118 127
119 void _updateExpanderView() { 128 void _updateExpanderView() {
120 if (_expander == null) { 129 if (_expander == null) {
121 return; 130 return;
122 } 131 }
123 if (!hasChildren()) { 132 if (!hasChildren()) {
124 _expander.style.visibility = 'hidden'; 133 _expander.style.visibility = 'hidden';
125 _expander.classes.remove('pointer'); 134 _expander.classes.remove('pointer');
(...skipping 20 matching lines...) Expand all
146 /// Fired when the tree row is being hidden. 155 /// Fired when the tree row is being hidden.
147 void onHide() { 156 void onHide() {
148 _tr = null; 157 _tr = null;
149 _expander = null; 158 _expander = null;
150 if (_tableColumns != null) { 159 if (_tableColumns != null) {
151 _tableColumns.clear(); 160 _tableColumns.clear();
152 } 161 }
153 if (flexColumns != null) { 162 if (flexColumns != null) {
154 flexColumns.clear(); 163 flexColumns.clear();
155 } 164 }
165 _cleanUpListeners();
156 } 166 }
157 } 167 }
158 168
159 class TableTree extends Observable { 169 class TableTree extends Observable {
160 final TableSectionElement tableBody; 170 final TableSectionElement tableBody;
161 final List<TableTreeRow> rows = []; 171 final List<TableTreeRow> rows = [];
162 final int columnCount; 172 final int columnCount;
163 Future _pendingOperation; 173 Future _pendingOperation;
164 /// Create a table tree with column [headers]. 174 /// Create a table tree with column [headers].
165 TableTree(this.tableBody, this.columnCount); 175 TableTree(this.tableBody, this.columnCount);
166 176
167 void clear() { 177 void clear() {
168 tableBody.children.clear(); 178 tableBody.children.clear();
179 for (var i = 0; i < rows.length; i++) {
180 rows[i]._cleanUpListeners();
181 }
169 rows.clear(); 182 rows.clear();
170 } 183 }
171 184
172 /// Initialize the table tree with the list of root children. 185 /// Initialize the table tree with the list of root children.
173 void initialize(TableTreeRow root) { 186 void initialize(TableTreeRow root) {
174 clear(); 187 clear();
175 root.onShow(); 188 root.onShow();
176 toggle(root); 189 toggle(root);
177 } 190 }
178 191
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 if (column != _sortColumnIndex) { 362 if (column != _sortColumnIndex) {
350 return columns[column].label + '\u2003'; 363 return columns[column].label + '\u2003';
351 } 364 }
352 return columns[column].label + (_sortDescending ? arrowUp : arrowDown); 365 return columns[column].label + (_sortDescending ? arrowUp : arrowDown);
353 } 366 }
354 367
355 dynamic getValue(int row, int column) { 368 dynamic getValue(int row, int column) {
356 return rows[row].values[column]; 369 return rows[row].values[column];
357 } 370 }
358 } 371 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/cpu_profile.dart ('k') | runtime/observatory/lib/src/cpu_profile/cpu_profile.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698