Commit 679a423b authored by Adam Barth's avatar Adam Barth

Explicitly dispose heavy C++ objects

This patch calls dispose() explicitly on a number of heavy C++ objects so that
they can be eagerly finalized instead of waiting for GC.
parent b628ff40
...@@ -59,6 +59,10 @@ abstract class Layer { ...@@ -59,6 +59,10 @@ abstract class Layer {
_nextSibling = null; _nextSibling = null;
_previousSibling = null; _previousSibling = null;
_parent = null; _parent = null;
_dispose();
}
void _dispose() {
} }
/// Override this function to upload this layer to the engine /// Override this function to upload this layer to the engine
...@@ -84,6 +88,11 @@ class PictureLayer extends Layer { ...@@ -84,6 +88,11 @@ class PictureLayer extends Layer {
/// The picture's coodinate system matches this layer's coodinate system /// The picture's coodinate system matches this layer's coodinate system
ui.Picture picture; ui.Picture picture;
void _dispose() {
super._dispose();
picture.dispose();
}
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
builder.addPicture(offset + layerOffset, picture, paintBounds); builder.addPicture(offset + layerOffset, picture, paintBounds);
} }
...@@ -181,6 +190,7 @@ class ContainerLayer extends Layer { ...@@ -181,6 +190,7 @@ class ContainerLayer extends Layer {
child._previousSibling = null; child._previousSibling = null;
child._nextSibling = null; child._nextSibling = null;
child._parent = null; child._parent = null;
child._dispose();
} }
/// Removes all of this layer's children from its child list /// Removes all of this layer's children from its child list
...@@ -191,12 +201,23 @@ class ContainerLayer extends Layer { ...@@ -191,12 +201,23 @@ class ContainerLayer extends Layer {
child._previousSibling = null; child._previousSibling = null;
child._nextSibling = null; child._nextSibling = null;
child._parent = null; child._parent = null;
child._dispose();
child = next; child = next;
} }
_firstChild = null; _firstChild = null;
_lastChild = null; _lastChild = null;
} }
void _dispose() {
super._dispose();
Layer child = _firstChild;
while (child != null) {
Layer next = child.nextSibling;
child._dispose();
child = next;
}
}
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
addChildrenToScene(builder, offset + layerOffset); addChildrenToScene(builder, offset + layerOffset);
} }
......
...@@ -122,7 +122,9 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox> ...@@ -122,7 +122,9 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
Rect bounds = Point.origin & (size * ui.window.devicePixelRatio); Rect bounds = Point.origin & (size * ui.window.devicePixelRatio);
ui.SceneBuilder builder = new ui.SceneBuilder(bounds); ui.SceneBuilder builder = new ui.SceneBuilder(bounds);
layer.addToScene(builder, Offset.zero); layer.addToScene(builder, Offset.zero);
ui.window.render(builder.build()); ui.Scene scene = builder.build();
ui.window.render(scene);
scene.dispose();
} finally { } finally {
ui.tracing.end('RenderView.compositeFrame'); ui.tracing.end('RenderView.compositeFrame');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment