diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/picture.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/picture.dart index 5fdc0ccb19..19e1d71519 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/picture.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/picture.dart @@ -6,7 +6,6 @@ import 'dart:typed_data'; import 'package:ui/ui.dart' as ui; -import '../profiler.dart'; import '../util.dart'; import 'canvas.dart'; import 'canvaskit_api.dart'; @@ -77,9 +76,6 @@ class CkPicture implements ui.Picture { return true; }()); ui.Picture.onDispose?.call(this); - if (Instrumentation.enabled) { - Instrumentation.instance.incrementCounter('Picture disposed'); - } _isDisposed = true; _ref.dispose(); } diff --git a/engine/src/flutter/lib/web_ui/test/canvaskit/native_memory_test.dart b/engine/src/flutter/lib/web_ui/test/canvaskit/native_memory_test.dart index 42a99d284b..3ccaa13c5d 100644 --- a/engine/src/flutter/lib/web_ui/test/canvaskit/native_memory_test.dart +++ b/engine/src/flutter/lib/web_ui/test/canvaskit/native_memory_test.dart @@ -81,6 +81,45 @@ void testMain() { // there must not be anything else calling into this object for anything // useful. }); + + test('dispose instrumentation', () { + Instrumentation.enabled = true; + Instrumentation.instance.debugCounters.clear(); + + final Object owner = Object(); + final TestSkDeletable nativeObject = TestSkDeletable(); + + expect(Instrumentation.instance.debugCounters, {}); + final UniqueRef ref = UniqueRef(owner, nativeObject, 'TestSkDeletable'); + expect(Instrumentation.instance.debugCounters, { + 'TestSkDeletable Created': 1, + }); + ref.dispose(); + expect(Instrumentation.instance.debugCounters, { + 'TestSkDeletable Created': 1, + 'TestSkDeletable Deleted': 1, + }); + }); + + test('collect instrumentation', () { + Instrumentation.enabled = true; + Instrumentation.instance.debugCounters.clear(); + + final Object owner = Object(); + final TestSkDeletable nativeObject = TestSkDeletable(); + + expect(Instrumentation.instance.debugCounters, {}); + final UniqueRef ref = UniqueRef(owner, nativeObject, 'TestSkDeletable'); + expect(Instrumentation.instance.debugCounters, { + 'TestSkDeletable Created': 1, + }); + ref.collect(); + expect(Instrumentation.instance.debugCounters, { + 'TestSkDeletable Created': 1, + 'TestSkDeletable Leaked': 1, + 'TestSkDeletable Deleted': 1, + }); + }); }); group(CountedRef, () {