Skip to content

Commit e2d5e8f

Browse files
authored
Instrumented PipelineOwner for leak tracking (#137494)
1 parent 7308207 commit e2d5e8f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/flutter/lib/src/rendering/object.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,17 @@ class PipelineOwner with DiagnosticableTreeMixin {
895895
this.onSemanticsOwnerCreated,
896896
this.onSemanticsUpdate,
897897
this.onSemanticsOwnerDisposed,
898-
});
898+
}){
899+
// TODO(polina-c): stop duplicating code across disposables
900+
// https://github.com/flutter/flutter/issues/137435
901+
if (kFlutterMemoryAllocationsEnabled) {
902+
MemoryAllocations.instance.dispatchObjectCreated(
903+
library: 'package:flutter/rendering.dart',
904+
className: '$PipelineOwner',
905+
object: this,
906+
);
907+
}
908+
}
899909

900910
/// Called when a render object associated with this pipeline owner wishes to
901911
/// update its visual appearance.
@@ -1433,6 +1443,9 @@ class PipelineOwner with DiagnosticableTreeMixin {
14331443
assert(rootNode == null);
14341444
assert(_manifold == null);
14351445
assert(_debugParent == null);
1446+
if (kFlutterMemoryAllocationsEnabled) {
1447+
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
1448+
}
14361449
_semanticsOwner?.dispose();
14371450
_semanticsOwner = null;
14381451
_nodesNeedingLayout.clear();

packages/flutter/test/rendering/object_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ import 'package:flutter/foundation.dart';
88
import 'package:flutter/material.dart';
99
import 'package:flutter/rendering.dart';
1010
import 'package:flutter_test/flutter_test.dart';
11+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
1112

1213
import 'rendering_tester.dart';
1314

1415
void main() {
1516
TestRenderingFlutterBinding.ensureInitialized();
1617

18+
test('PipelineOwner dispatches memory events', () async {
19+
await expectLater(
20+
await memoryEvents(() => PipelineOwner().dispose(), PipelineOwner),
21+
areCreateAndDispose,
22+
);
23+
});
24+
1725
test('ensure frame is scheduled for markNeedsSemanticsUpdate', () {
1826
// Initialize all bindings because owner.flushSemantics() requires a window
1927
final TestRenderObject renderObject = TestRenderObject();

0 commit comments

Comments
 (0)