Instrumented PipelineOwner for leak tracking (#137494)

This commit is contained in:
Binni Goel
2023-11-02 20:18:22 +05:30
committed by GitHub
parent 7308207ca1
commit e2d5e8fdce
2 changed files with 22 additions and 1 deletions

View File

@@ -895,7 +895,17 @@ class PipelineOwner with DiagnosticableTreeMixin {
this.onSemanticsOwnerCreated,
this.onSemanticsUpdate,
this.onSemanticsOwnerDisposed,
});
}){
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/rendering.dart',
className: '$PipelineOwner',
object: this,
);
}
}
/// Called when a render object associated with this pipeline owner wishes to
/// update its visual appearance.
@@ -1433,6 +1443,9 @@ class PipelineOwner with DiagnosticableTreeMixin {
assert(rootNode == null);
assert(_manifold == null);
assert(_debugParent == null);
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_semanticsOwner?.dispose();
_semanticsOwner = null;
_nodesNeedingLayout.clear();

View File

@@ -8,12 +8,20 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import 'rendering_tester.dart';
void main() {
TestRenderingFlutterBinding.ensureInitialized();
test('PipelineOwner dispatches memory events', () async {
await expectLater(
await memoryEvents(() => PipelineOwner().dispose(), PipelineOwner),
areCreateAndDispose,
);
});
test('ensure frame is scheduled for markNeedsSemanticsUpdate', () {
// Initialize all bindings because owner.flushSemantics() requires a window
final TestRenderObject renderObject = TestRenderObject();