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;
import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
const String _flutterWidgetsLibrary = 'package:flutter/widgets.dart';
/// A [dart:ui.Image] object with its corresponding scale.
///
/// ImageInfo objects are used by [ImageStream] objects to represent the
......@@ -437,6 +439,15 @@ class ImageStream with Diagnosticable {
class ImageStreamCompleterHandle {
ImageStreamCompleterHandle._(ImageStreamCompleter this._completer) {
_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;
......@@ -453,6 +464,11 @@ class ImageStreamCompleterHandle {
_completer!._keepAliveHandles -= 1;
_completer!._maybeDispose();
_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() {
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