Merge pull request #350 from abarth/dispose_host_objects

Explicitly dispose heavy C++ objects
This commit is contained in:
Adam Barth 2015-11-12 17:24:43 -08:00
commit 4e329a6731
2 changed files with 24 additions and 1 deletions

View File

@ -59,6 +59,10 @@ abstract class Layer {
_nextSibling = null;
_previousSibling = null;
_parent = null;
_dispose();
}
void _dispose() {
}
/// Override this function to upload this layer to the engine
@ -84,6 +88,11 @@ class PictureLayer extends Layer {
/// The picture's coodinate system matches this layer's coodinate system
ui.Picture picture;
void _dispose() {
super._dispose();
picture.dispose();
}
void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
builder.addPicture(offset + layerOffset, picture, paintBounds);
}
@ -181,6 +190,7 @@ class ContainerLayer extends Layer {
child._previousSibling = null;
child._nextSibling = null;
child._parent = null;
child._dispose();
}
/// Removes all of this layer's children from its child list
@ -191,12 +201,23 @@ class ContainerLayer extends Layer {
child._previousSibling = null;
child._nextSibling = null;
child._parent = null;
child._dispose();
child = next;
}
_firstChild = 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) {
addChildrenToScene(builder, offset + layerOffset);
}

View File

@ -122,7 +122,9 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
Rect bounds = Point.origin & (size * ui.window.devicePixelRatio);
ui.SceneBuilder builder = new ui.SceneBuilder(bounds);
layer.addToScene(builder, Offset.zero);
ui.window.render(builder.build());
ui.Scene scene = builder.build();
ui.window.render(scene);
scene.dispose();
} finally {
ui.tracing.end('RenderView.compositeFrame');
}