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

Private disposables should dispatch creation and disposal events. (#141535)

parent 1a2c3151
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:ui' show lerpDouble; import 'dart:ui' show lerpDouble;
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -147,7 +148,17 @@ class _AnimationTuple { ...@@ -147,7 +148,17 @@ class _AnimationTuple {
required this.startAnimation, required this.startAnimation,
required this.endAnimation, required this.endAnimation,
required this.gapAnimation, required this.gapAnimation,
}); }) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/material.dart',
className: '$_AnimationTuple',
object: this,
);
}
}
final AnimationController controller; final AnimationController controller;
final CurvedAnimation startAnimation; final CurvedAnimation startAnimation;
...@@ -157,6 +168,9 @@ class _AnimationTuple { ...@@ -157,6 +168,9 @@ class _AnimationTuple {
@mustCallSuper @mustCallSuper
void dispose() { void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
controller.dispose(); controller.dispose();
startAnimation.dispose(); startAnimation.dispose();
endAnimation.dispose(); endAnimation.dispose();
......
...@@ -437,6 +437,15 @@ class _IndicatorPainter extends CustomPainter { ...@@ -437,6 +437,15 @@ class _IndicatorPainter extends CustomPainter {
this.dividerHeight, this.dividerHeight,
required this.showDivider, required this.showDivider,
}) : super(repaint: controller.animation) { }) : super(repaint: controller.animation) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/material.dart',
className: '$_IndicatorPainter',
object: this,
);
}
if (old != null) { if (old != null) {
saveTabOffsets(old._currentTabOffsets, old._currentTextDirection); saveTabOffsets(old._currentTabOffsets, old._currentTextDirection);
} }
...@@ -466,6 +475,9 @@ class _IndicatorPainter extends CustomPainter { ...@@ -466,6 +475,9 @@ class _IndicatorPainter extends CustomPainter {
} }
void dispose() { void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_painter?.dispose(); _painter?.dispose();
} }
......
...@@ -6,6 +6,7 @@ import 'dart:async'; ...@@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:ui'; import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -904,7 +905,17 @@ class _DialPainter extends CustomPainter { ...@@ -904,7 +905,17 @@ class _DialPainter extends CustomPainter {
required this.radius, required this.radius,
required this.textDirection, required this.textDirection,
required this.selectedValue, required this.selectedValue,
}) : super(repaint: PaintingBinding.instance.systemFonts); }) : super(repaint: PaintingBinding.instance.systemFonts) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/material.dart',
className: '$_DialPainter',
object: this,
);
}
}
final List<_TappableLabel> primaryLabels; final List<_TappableLabel> primaryLabels;
final List<_TappableLabel> selectedLabels; final List<_TappableLabel> selectedLabels;
...@@ -920,6 +931,9 @@ class _DialPainter extends CustomPainter { ...@@ -920,6 +931,9 @@ class _DialPainter extends CustomPainter {
final int selectedValue; final int selectedValue;
void dispose() { void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
for (final _TappableLabel label in primaryLabels) { for (final _TappableLabel label in primaryLabels) {
label.painter.dispose(); label.painter.dispose();
} }
......
...@@ -311,7 +311,17 @@ abstract interface class DecorationImagePainter { ...@@ -311,7 +311,17 @@ abstract interface class DecorationImagePainter {
} }
class _DecorationImagePainter implements DecorationImagePainter { class _DecorationImagePainter implements DecorationImagePainter {
_DecorationImagePainter._(this._details, this._onChanged); _DecorationImagePainter._(this._details, this._onChanged) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/painting.dart',
className: '$_DecorationImagePainter',
object: this,
);
}
}
final DecorationImage _details; final DecorationImage _details;
final VoidCallback _onChanged; final VoidCallback _onChanged;
...@@ -404,6 +414,9 @@ class _DecorationImagePainter implements DecorationImagePainter { ...@@ -404,6 +414,9 @@ class _DecorationImagePainter implements DecorationImagePainter {
@override @override
void dispose() { void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_imageStream?.removeListener(ImageStreamListener( _imageStream?.removeListener(ImageStreamListener(
_handleImage, _handleImage,
onError: _details.onError, onError: _details.onError,
...@@ -801,7 +814,17 @@ class _BlendedDecorationImage implements DecorationImage { ...@@ -801,7 +814,17 @@ class _BlendedDecorationImage implements DecorationImage {
} }
class _BlendedDecorationImagePainter implements DecorationImagePainter { class _BlendedDecorationImagePainter implements DecorationImagePainter {
_BlendedDecorationImagePainter._(this.a, this.b, this.t); _BlendedDecorationImagePainter._(this.a, this.b, this.t) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/painting.dart',
className: '$_BlendedDecorationImagePainter',
object: this,
);
}
}
final DecorationImagePainter? a; final DecorationImagePainter? a;
final DecorationImagePainter? b; final DecorationImagePainter? b;
...@@ -817,6 +840,9 @@ class _BlendedDecorationImagePainter implements DecorationImagePainter { ...@@ -817,6 +840,9 @@ class _BlendedDecorationImagePainter implements DecorationImagePainter {
@override @override
void dispose() { void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
a?.dispose(); a?.dispose();
b?.dispose(); b?.dispose();
} }
......
...@@ -606,7 +606,17 @@ abstract class _CachedImageBase { ...@@ -606,7 +606,17 @@ abstract class _CachedImageBase {
_CachedImageBase( _CachedImageBase(
this.completer, { this.completer, {
this.sizeBytes, this.sizeBytes,
}) : handle = completer.keepAlive(); }) : handle = completer.keepAlive() {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/painting.dart',
className: '$_CachedImageBase',
object: this,
);
}
}
final ImageStreamCompleter completer; final ImageStreamCompleter completer;
int? sizeBytes; int? sizeBytes;
...@@ -615,6 +625,9 @@ abstract class _CachedImageBase { ...@@ -615,6 +625,9 @@ abstract class _CachedImageBase {
@mustCallSuper @mustCallSuper
void dispose() { void dispose() {
assert(handle != null); assert(handle != null);
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
// Give any interested parties a chance to listen to the stream before we // Give any interested parties a chance to listen to the stream before we
// potentially dispose it. // potentially dispose it.
SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) {
......
...@@ -754,6 +754,9 @@ class RenderingFlutterBinding extends BindingBase with GestureBinding, Scheduler ...@@ -754,6 +754,9 @@ class RenderingFlutterBinding extends BindingBase with GestureBinding, Scheduler
/// A [PipelineManifold] implementation that is backed by the [RendererBinding]. /// A [PipelineManifold] implementation that is backed by the [RendererBinding].
class _BindingPipelineManifold extends ChangeNotifier implements PipelineManifold { class _BindingPipelineManifold extends ChangeNotifier implements PipelineManifold {
_BindingPipelineManifold(this._binding) { _BindingPipelineManifold(this._binding) {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
_binding.addSemanticsEnabledListener(notifyListeners); _binding.addSemanticsEnabledListener(notifyListeners);
} }
......
...@@ -494,7 +494,17 @@ class _DraggableSheetExtent { ...@@ -494,7 +494,17 @@ class _DraggableSheetExtent {
_currentSize = currentSize ?? ValueNotifier<double>(initialSize), _currentSize = currentSize ?? ValueNotifier<double>(initialSize),
availablePixels = double.infinity, availablePixels = double.infinity,
hasDragged = hasDragged ?? false, hasDragged = hasDragged ?? false,
hasChanged = hasChanged ?? false; hasChanged = hasChanged ?? false {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/widgets.dart',
className: '$_DraggableSheetExtent',
object: this,
);
}
}
VoidCallback? _cancelActivity; VoidCallback? _cancelActivity;
...@@ -590,6 +600,9 @@ class _DraggableSheetExtent { ...@@ -590,6 +600,9 @@ class _DraggableSheetExtent {
} }
void dispose() { void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_currentSize.dispose(); _currentSize.dispose();
} }
......
...@@ -1831,6 +1831,18 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier { ...@@ -1831,6 +1831,18 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier {
// This doesn't extend ChangeNotifier because the callback passes the updated // This doesn't extend ChangeNotifier because the callback passes the updated
// value, and ChangeNotifier requires using VoidCallback. // value, and ChangeNotifier requires using VoidCallback.
class _HighlightModeManager { class _HighlightModeManager {
_HighlightModeManager() {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/widgets.dart',
className: '$_HighlightModeManager',
object: this,
);
}
}
// If set, indicates if the last interaction detected was touch or not. If // If set, indicates if the last interaction detected was touch or not. If
// null, no interactions have occurred yet. // null, no interactions have occurred yet.
bool? _lastInteractionWasTouch; bool? _lastInteractionWasTouch;
...@@ -1888,6 +1900,9 @@ class _HighlightModeManager { ...@@ -1888,6 +1900,9 @@ class _HighlightModeManager {
@mustCallSuper @mustCallSuper
void dispose() { void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
if (ServicesBinding.instance.keyEventManager.keyMessageHandler == handleKeyMessage) { if (ServicesBinding.instance.keyEventManager.keyMessageHandler == handleKeyMessage) {
GestureBinding.instance.pointerRouter.removeGlobalRoute(handlePointerEvent); GestureBinding.instance.pointerRouter.removeGlobalRoute(handlePointerEvent);
ServicesBinding.instance.keyEventManager.keyMessageHandler = null; ServicesBinding.instance.keyEventManager.keyMessageHandler = null;
......
...@@ -510,6 +510,15 @@ class _HeroFlightManifest { ...@@ -510,6 +510,15 @@ class _HeroFlightManifest {
// Builds the in-flight hero widget. // Builds the in-flight hero widget.
class _HeroFlight { class _HeroFlight {
_HeroFlight(this.onFlightEnded) { _HeroFlight(this.onFlightEnded) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/widgets.dart',
className: '$_HeroFlight',
object: this,
);
}
_proxyAnimation = ProxyAnimation()..addStatusListener(_handleAnimationUpdate); _proxyAnimation = ProxyAnimation()..addStatusListener(_handleAnimationUpdate);
} }
...@@ -614,6 +623,9 @@ class _HeroFlight { ...@@ -614,6 +623,9 @@ class _HeroFlight {
/// Releases resources. /// Releases resources.
@mustCallSuper @mustCallSuper
void dispose() { void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
if (overlayEntry != null) { if (overlayEntry != null) {
overlayEntry!.remove(); overlayEntry!.remove();
overlayEntry!.dispose(); overlayEntry!.dispose();
...@@ -1008,7 +1020,7 @@ class HeroController extends NavigatorObserver { ...@@ -1008,7 +1020,7 @@ class HeroController extends NavigatorObserver {
} }
void _handleFlightEnded(_HeroFlight flight) { void _handleFlightEnded(_HeroFlight flight) {
_flights.remove(flight.manifest.tag); _flights.remove(flight.manifest.tag)?.dispose();
} }
Widget _defaultHeroFlightShuttleBuilder( Widget _defaultHeroFlightShuttleBuilder(
......
...@@ -596,6 +596,15 @@ class _NestedScrollCoordinator implements ScrollActivityDelegate, ScrollHoldCont ...@@ -596,6 +596,15 @@ class _NestedScrollCoordinator implements ScrollActivityDelegate, ScrollHoldCont
this._onHasScrolledBodyChanged, this._onHasScrolledBodyChanged,
this._floatHeaderSlivers, this._floatHeaderSlivers,
) { ) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/widgets.dart',
className: '$_NestedScrollCoordinator',
object: this,
);
}
final double initialScrollOffset = _parent?.initialScrollOffset ?? 0.0; final double initialScrollOffset = _parent?.initialScrollOffset ?? 0.0;
_outerController = _NestedScrollController( _outerController = _NestedScrollController(
this, this,
...@@ -1123,6 +1132,9 @@ class _NestedScrollCoordinator implements ScrollActivityDelegate, ScrollHoldCont ...@@ -1123,6 +1132,9 @@ class _NestedScrollCoordinator implements ScrollActivityDelegate, ScrollHoldCont
@mustCallSuper @mustCallSuper
void dispose() { void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_currentDrag?.dispose(); _currentDrag?.dispose();
_currentDrag = null; _currentDrag = null;
_outerController.dispose(); _outerController.dispose();
......
...@@ -308,6 +308,9 @@ class _GlowController extends ChangeNotifier { ...@@ -308,6 +308,9 @@ class _GlowController extends ChangeNotifier {
required Axis axis, required Axis axis,
}) : _color = color, }) : _color = color,
_axis = axis { _axis = axis {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
_glowController = AnimationController(vsync: vsync) _glowController = AnimationController(vsync: vsync)
..addStatusListener(_changePhase); ..addStatusListener(_changePhase);
final Animation<double> decelerator = CurvedAnimation( final Animation<double> decelerator = CurvedAnimation(
...@@ -812,6 +815,9 @@ enum _StretchState { ...@@ -812,6 +815,9 @@ enum _StretchState {
class _StretchController extends ChangeNotifier { class _StretchController extends ChangeNotifier {
_StretchController({ required TickerProvider vsync }) { _StretchController({ required TickerProvider vsync }) {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
_stretchController = AnimationController(vsync: vsync) _stretchController = AnimationController(vsync: vsync)
..addStatusListener(_changePhase); ..addStatusListener(_changePhase);
final Animation<double> decelerator = CurvedAnimation( final Animation<double> decelerator = CurvedAnimation(
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
...@@ -1339,6 +1340,15 @@ class _DragInfo extends Drag { ...@@ -1339,6 +1340,15 @@ class _DragInfo extends Drag {
this.proxyDecorator, this.proxyDecorator,
required this.tickerProvider, required this.tickerProvider,
}) { }) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/widgets.dart',
className: '$_DragInfo',
object: this,
);
}
final RenderBox itemRenderBox = item.context.findRenderObject()! as RenderBox; final RenderBox itemRenderBox = item.context.findRenderObject()! as RenderBox;
listState = item._listState; listState = item._listState;
index = item.index; index = item.index;
...@@ -1371,6 +1381,9 @@ class _DragInfo extends Drag { ...@@ -1371,6 +1381,9 @@ class _DragInfo extends Drag {
AnimationController? _proxyAnimation; AnimationController? _proxyAnimation;
void dispose() { void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_proxyAnimation?.dispose(); _proxyAnimation?.dispose();
} }
......
...@@ -182,6 +182,15 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindi ...@@ -182,6 +182,15 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindi
class _SemanticsClient extends ChangeNotifier { class _SemanticsClient extends ChangeNotifier {
_SemanticsClient(PipelineOwner pipelineOwner) { _SemanticsClient(PipelineOwner pipelineOwner) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/widgets.dart',
className: '$_SemanticsClient',
object: this,
);
}
_semanticsHandle = pipelineOwner.ensureSemantics( _semanticsHandle = pipelineOwner.ensureSemantics(
listener: _didUpdateSemantics, listener: _didUpdateSemantics,
); );
...@@ -191,6 +200,9 @@ class _SemanticsClient extends ChangeNotifier { ...@@ -191,6 +200,9 @@ class _SemanticsClient extends ChangeNotifier {
@override @override
void dispose() { void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_semanticsHandle!.dispose(); _semanticsHandle!.dispose();
_semanticsHandle = null; _semanticsHandle = null;
super.dispose(); super.dispose();
......
...@@ -336,7 +336,17 @@ class _ScreenshotContainerLayer extends OffsetLayer { ...@@ -336,7 +336,17 @@ class _ScreenshotContainerLayer extends OffsetLayer {
class _ScreenshotData { class _ScreenshotData {
_ScreenshotData({ _ScreenshotData({
required this.target, required this.target,
}) : containerLayer = _ScreenshotContainerLayer(); }) : containerLayer = _ScreenshotContainerLayer() {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/widgets.dart',
className: '$_ScreenshotData',
object: this,
);
}
}
/// Target to take a screenshot of. /// Target to take a screenshot of.
final RenderObject target; final RenderObject target;
...@@ -376,6 +386,9 @@ class _ScreenshotData { ...@@ -376,6 +386,9 @@ class _ScreenshotData {
/// Releases allocated resources. /// Releases allocated resources.
@mustCallSuper @mustCallSuper
void dispose() { void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
containerLayer.dispose(); containerLayer.dispose();
} }
} }
......
...@@ -131,7 +131,7 @@ Future<_EventStats> _activateFlutterObjectsAndReturnCountOfEvents() async { ...@@ -131,7 +131,7 @@ Future<_EventStats> _activateFlutterObjectsAndReturnCountOfEvents() async {
final _TestElement element = _TestElement(); result.creations++; final _TestElement element = _TestElement(); result.creations++;
final RenderObject renderObject = _TestRenderObject(); result.creations++; final RenderObject renderObject = _TestRenderObject(); result.creations++;
element.makeInactive(); result.creations += 3; // 1 for the new BuildOwner, 1 for the new FocusManager, 1 for the new FocusScopeNode element.makeInactive(); result.creations += 4; // 1 for the new BuildOwner, 1 for the new FocusManager, 1 for the new FocusScopeNode, 1 for the new _HighlightModeManager
element.unmount(); result.disposals += 2; // 1 for the old BuildOwner, 1 for the element element.unmount(); result.disposals += 2; // 1 for the old BuildOwner, 1 for the element
renderObject.dispose(); result.disposals += 1; renderObject.dispose(); result.disposals += 1;
......
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