Instrument more disposables. (#137309)
This commit is contained in:
parent
fea561301b
commit
65c71d4294
@ -246,7 +246,9 @@ class AnimationController extends Animation<double>
|
|||||||
required TickerProvider vsync,
|
required TickerProvider vsync,
|
||||||
}) : assert(upperBound >= lowerBound),
|
}) : assert(upperBound >= lowerBound),
|
||||||
_direction = _AnimationDirection.forward {
|
_direction = _AnimationDirection.forward {
|
||||||
_maybeDispatchObjectCreation();
|
if (kFlutterMemoryAllocationsEnabled) {
|
||||||
|
_maybeDispatchObjectCreation();
|
||||||
|
}
|
||||||
_ticker = vsync.createTicker(_tick);
|
_ticker = vsync.createTicker(_tick);
|
||||||
_internalSetValue(value ?? lowerBound);
|
_internalSetValue(value ?? lowerBound);
|
||||||
}
|
}
|
||||||
@ -278,7 +280,9 @@ class AnimationController extends Animation<double>
|
|||||||
}) : lowerBound = double.negativeInfinity,
|
}) : lowerBound = double.negativeInfinity,
|
||||||
upperBound = double.infinity,
|
upperBound = double.infinity,
|
||||||
_direction = _AnimationDirection.forward {
|
_direction = _AnimationDirection.forward {
|
||||||
_maybeDispatchObjectCreation();
|
if (kFlutterMemoryAllocationsEnabled) {
|
||||||
|
_maybeDispatchObjectCreation();
|
||||||
|
}
|
||||||
_ticker = vsync.createTicker(_tick);
|
_ticker = vsync.createTicker(_tick);
|
||||||
_internalSetValue(value);
|
_internalSetValue(value);
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ import 'framework.dart';
|
|||||||
import 'lookup_boundary.dart';
|
import 'lookup_boundary.dart';
|
||||||
import 'ticker_provider.dart';
|
import 'ticker_provider.dart';
|
||||||
|
|
||||||
|
const String _flutterWidgetsLibrary = 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// late BuildContext context;
|
// late BuildContext context;
|
||||||
|
|
||||||
@ -81,7 +83,11 @@ class OverlayEntry implements Listenable {
|
|||||||
bool opaque = false,
|
bool opaque = false,
|
||||||
bool maintainState = false,
|
bool maintainState = false,
|
||||||
}) : _opaque = opaque,
|
}) : _opaque = opaque,
|
||||||
_maintainState = maintainState;
|
_maintainState = maintainState {
|
||||||
|
if (kFlutterMemoryAllocationsEnabled) {
|
||||||
|
_maybeDispatchObjectCreation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// This entry will include the widget built by this builder in the overlay at
|
/// This entry will include the widget built by this builder in the overlay at
|
||||||
/// the entry's position.
|
/// the entry's position.
|
||||||
@ -140,6 +146,19 @@ class OverlayEntry implements Listenable {
|
|||||||
/// The currently mounted `_OverlayEntryWidgetState` built using this [OverlayEntry].
|
/// The currently mounted `_OverlayEntryWidgetState` built using this [OverlayEntry].
|
||||||
ValueNotifier<_OverlayEntryWidgetState?>? _overlayEntryStateNotifier = ValueNotifier<_OverlayEntryWidgetState?>(null);
|
ValueNotifier<_OverlayEntryWidgetState?>? _overlayEntryStateNotifier = ValueNotifier<_OverlayEntryWidgetState?>(null);
|
||||||
|
|
||||||
|
// TODO(polina-c): stop duplicating code across disposables
|
||||||
|
// https://github.com/flutter/flutter/issues/137435
|
||||||
|
/// Dispatches event of object creation to [MemoryAllocations.instance].
|
||||||
|
void _maybeDispatchObjectCreation() {
|
||||||
|
if (kFlutterMemoryAllocationsEnabled) {
|
||||||
|
MemoryAllocations.instance.dispatchObjectCreated(
|
||||||
|
library: _flutterWidgetsLibrary,
|
||||||
|
className: '$OverlayEntry',
|
||||||
|
object: this,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void addListener(VoidCallback listener) {
|
void addListener(VoidCallback listener) {
|
||||||
assert(!_disposedByOwner);
|
assert(!_disposedByOwner);
|
||||||
@ -216,6 +235,9 @@ class OverlayEntry implements Listenable {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
assert(!_disposedByOwner);
|
assert(!_disposedByOwner);
|
||||||
assert(_overlay == null, 'An OverlayEntry must first be removed from the Overlay before dispose is called.');
|
assert(_overlay == null, 'An OverlayEntry must first be removed from the Overlay before dispose is called.');
|
||||||
|
if (kFlutterMemoryAllocationsEnabled) {
|
||||||
|
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
|
||||||
|
}
|
||||||
_disposedByOwner = true;
|
_disposedByOwner = true;
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
// If we're still mounted when disposed, then this will be disposed in
|
// If we're still mounted when disposed, then this will be disposed in
|
||||||
|
@ -33,6 +33,9 @@ Future<void> testExecutable(FutureOr<void> Function() testMain) {
|
|||||||
.withTrackedAll()
|
.withTrackedAll()
|
||||||
.withIgnored(
|
.withIgnored(
|
||||||
allNotGCed: true,
|
allNotGCed: true,
|
||||||
|
notDisposed: <String, int?>{
|
||||||
|
'OverlayEntry': null,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Enable golden file testing using Skia Gold.
|
// Enable golden file testing using Skia Gold.
|
||||||
|
@ -10,6 +10,18 @@ import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
|
|||||||
import 'semantics_tester.dart';
|
import 'semantics_tester.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
test('OverlayEntry dispatches memory events', () async {
|
||||||
|
await expectLater(
|
||||||
|
await memoryEvents(
|
||||||
|
() => OverlayEntry(
|
||||||
|
builder: (BuildContext context) => Container(),
|
||||||
|
).dispose(),
|
||||||
|
OverlayEntry,
|
||||||
|
),
|
||||||
|
areCreateAndDispose,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
testWidgetsWithLeakTracking('OverflowEntries context contains Overlay', (WidgetTester tester) async {
|
testWidgetsWithLeakTracking('OverflowEntries context contains Overlay', (WidgetTester tester) async {
|
||||||
final GlobalKey overlayKey = GlobalKey();
|
final GlobalKey overlayKey = GlobalKey();
|
||||||
bool didBuild = false;
|
bool didBuild = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user