Skip to content

Commit 97ad45a

Browse files
[skwasm] Decrease reliance on finalizers/GC (#172187)
Some changes which make Skwasm less dependent on GC cycles to free its native resources: * Explicitly clean up pictures clipped by the scene view * Free native `ParagraphBuilder` when `build()` is called * Restructure `TextStyle`, `ParagraphStyle`, `StrutStyle` and `LineMetrics` so that they don't persistently hang on to native objects beyond a paragraph build cycle. This addresses flutter/flutter#170889
1 parent 0669195 commit 97ad45a

4 files changed

Lines changed: 197 additions & 196 deletions

File tree

engine/src/flutter/lib/web_ui/lib/src/engine/scene_view.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class EngineSceneView {
9797
final List<LayerSlice?> slices = scene.rootLayer.slices;
9898
final List<ScenePicture> picturesToRender = <ScenePicture>[];
9999
final List<ScenePicture> originalPicturesToRender = <ScenePicture>[];
100+
final List<ScenePicture> picturesToFree = <ScenePicture>[];
100101
for (final LayerSlice? slice in slices) {
101102
if (slice == null) {
102103
continue;
@@ -111,7 +112,9 @@ class EngineSceneView {
111112
picturesToRender.add(slice.picture);
112113
} else {
113114
originalPicturesToRender.add(slice.picture);
114-
picturesToRender.add(pictureRenderer.clipPicture(slice.picture, clippedRect));
115+
final clippedPicture = pictureRenderer.clipPicture(slice.picture, clippedRect);
116+
picturesToRender.add(clippedPicture);
117+
picturesToFree.add(clippedPicture);
115118
}
116119
}
117120
final Map<ScenePicture, DomImageBitmap> renderMap;
@@ -130,6 +133,10 @@ class EngineSceneView {
130133
}
131134
recorder?.submitTimings();
132135

136+
for (final p in picturesToFree) {
137+
p.dispose();
138+
}
139+
133140
final List<SliceContainer?> reusableContainers = List<SliceContainer?>.from(containers);
134141
final List<SliceContainer> newContainers = <SliceContainer>[];
135142
for (final LayerSlice? slice in slices) {

0 commit comments

Comments
 (0)