Unverified Commit 39f29741 authored by Binni Goel's avatar Binni Goel Committed by GitHub

Instrument ImageStreamCompleterHandle for LeakTracking (#137482)

parent e2d5e8fd
...@@ -8,6 +8,8 @@ import 'dart:ui' as ui show Codec, FrameInfo, Image; ...@@ -8,6 +8,8 @@ import 'dart:ui' as ui show Codec, FrameInfo, Image;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
const String _flutterWidgetsLibrary = 'package:flutter/widgets.dart';
/// A [dart:ui.Image] object with its corresponding scale. /// A [dart:ui.Image] object with its corresponding scale.
/// ///
/// ImageInfo objects are used by [ImageStream] objects to represent the /// ImageInfo objects are used by [ImageStream] objects to represent the
...@@ -437,6 +439,15 @@ class ImageStream with Diagnosticable { ...@@ -437,6 +439,15 @@ class ImageStream with Diagnosticable {
class ImageStreamCompleterHandle { class ImageStreamCompleterHandle {
ImageStreamCompleterHandle._(ImageStreamCompleter this._completer) { ImageStreamCompleterHandle._(ImageStreamCompleter this._completer) {
_completer!._keepAliveHandles += 1; _completer!._keepAliveHandles += 1;
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectCreated(
library: _flutterWidgetsLibrary,
className: '$ImageStreamCompleterHandle',
object: this,
);
}
} }
ImageStreamCompleter? _completer; ImageStreamCompleter? _completer;
...@@ -453,6 +464,11 @@ class ImageStreamCompleterHandle { ...@@ -453,6 +464,11 @@ class ImageStreamCompleterHandle {
_completer!._keepAliveHandles -= 1; _completer!._keepAliveHandles -= 1;
_completer!._maybeDispose(); _completer!._maybeDispose();
_completer = null; _completer = null;
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
} }
} }
......
...@@ -871,4 +871,21 @@ void main() { ...@@ -871,4 +871,21 @@ void main() {
expect(synchronouslyCalled, false); expect(synchronouslyCalled, false);
}); });
test('ImageStreamCompleterHandle dispatches memory events', () async {
await expectLater(
await memoryEvents(
() {
final StreamController<ImageChunkEvent> streamController = StreamController<ImageChunkEvent>();
addTearDown(streamController.close);
final ImageStreamCompleterHandle imageStreamCompleterHandle = FakeEventReportingImageStreamCompleter(
chunkEvents: streamController.stream,
).keepAlive();
imageStreamCompleterHandle.dispose();
},
ImageStreamCompleterHandle,
),
areCreateAndDispose,
);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment