Unverified Commit cdcacd06 authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

PerformanceModeRequestHandle should dispatch creation and disposal events. (#137642)

parent 64d39370
......@@ -196,7 +196,17 @@ typedef _PerformanceModeCleanupCallback = VoidCallback;
/// To create a [PerformanceModeRequestHandle], use [SchedulerBinding.requestPerformanceMode].
/// The component that makes the request is responsible for disposing the handle.
class PerformanceModeRequestHandle {
PerformanceModeRequestHandle._(_PerformanceModeCleanupCallback this._cleanup);
PerformanceModeRequestHandle._(_PerformanceModeCleanupCallback this._cleanup) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/scheduler.dart',
className: '$PerformanceModeRequestHandle',
object: this,
);
}
}
_PerformanceModeCleanupCallback? _cleanup;
......@@ -206,6 +216,11 @@ class PerformanceModeRequestHandle {
/// This method must only be called once per object.
void dispose() {
assert(_cleanup != null);
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_cleanup!();
_cleanup = null;
}
......
......@@ -7,6 +7,7 @@ import 'dart:ui';
import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
late SchedulerBinding binding;
......@@ -53,4 +54,14 @@ void main() {
requestHandle2?.dispose();
expect(binding.debugGetRequestedPerformanceMode(), isNull);
});
test('PerformanceModeRequestHandle dispatches memory events', () async {
await expectLater(
await memoryEvents(
() => binding.requestPerformanceMode(DartPerformanceMode.latency)!.dispose(),
PerformanceModeRequestHandle,
),
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