Skip to content

Commit

Permalink
Private disposables should dispatch creation and disposal events. (#1…
Browse files Browse the repository at this point in the history
…41535)
  • Loading branch information
ksokolovskyi authored Jan 14, 2024
1 parent 1a2c315 commit e5f62cc
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 9 deletions.
16 changes: 15 additions & 1 deletion packages/flutter/lib/src/material/mergeable_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'dart:ui' show lerpDouble;

import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

Expand Down Expand Up @@ -147,7 +148,17 @@ class _AnimationTuple {
required this.startAnimation,
required this.endAnimation,
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 CurvedAnimation startAnimation;
Expand All @@ -157,6 +168,9 @@ class _AnimationTuple {

@mustCallSuper
void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
controller.dispose();
startAnimation.dispose();
endAnimation.dispose();
Expand Down
12 changes: 12 additions & 0 deletions packages/flutter/lib/src/material/tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,15 @@ class _IndicatorPainter extends CustomPainter {
this.dividerHeight,
required this.showDivider,
}) : 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) {
saveTabOffsets(old._currentTabOffsets, old._currentTextDirection);
}
Expand Down Expand Up @@ -466,6 +475,9 @@ class _IndicatorPainter extends CustomPainter {
}

void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_painter?.dispose();
}

Expand Down
16 changes: 15 additions & 1 deletion packages/flutter/lib/src/material/time_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:math' as math;
import 'dart:ui';

import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
Expand Down Expand Up @@ -904,7 +905,17 @@ class _DialPainter extends CustomPainter {
required this.radius,
required this.textDirection,
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> selectedLabels;
Expand All @@ -920,6 +931,9 @@ class _DialPainter extends CustomPainter {
final int selectedValue;

void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
for (final _TappableLabel label in primaryLabels) {
label.painter.dispose();
}
Expand Down
30 changes: 28 additions & 2 deletions packages/flutter/lib/src/painting/decoration_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,17 @@ abstract interface class 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 VoidCallback _onChanged;
Expand Down Expand Up @@ -404,6 +414,9 @@ class _DecorationImagePainter implements DecorationImagePainter {

@override
void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_imageStream?.removeListener(ImageStreamListener(
_handleImage,
onError: _details.onError,
Expand Down Expand Up @@ -801,7 +814,17 @@ class _BlendedDecorationImage implements DecorationImage {
}

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? b;
Expand All @@ -817,6 +840,9 @@ class _BlendedDecorationImagePainter implements DecorationImagePainter {

@override
void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
a?.dispose();
b?.dispose();
}
Expand Down
15 changes: 14 additions & 1 deletion packages/flutter/lib/src/painting/image_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,17 @@ abstract class _CachedImageBase {
_CachedImageBase(
this.completer, {
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;
int? sizeBytes;
Expand All @@ -615,6 +625,9 @@ abstract class _CachedImageBase {
@mustCallSuper
void dispose() {
assert(handle != null);
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
// Give any interested parties a chance to listen to the stream before we
// potentially dispose it.
SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) {
Expand Down
3 changes: 3 additions & 0 deletions packages/flutter/lib/src/rendering/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,9 @@ class RenderingFlutterBinding extends BindingBase with GestureBinding, Scheduler
/// A [PipelineManifold] implementation that is backed by the [RendererBinding].
class _BindingPipelineManifold extends ChangeNotifier implements PipelineManifold {
_BindingPipelineManifold(this._binding) {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
_binding.addSemanticsEnabledListener(notifyListeners);
}

Expand Down
15 changes: 14 additions & 1 deletion packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,17 @@ class _DraggableSheetExtent {
_currentSize = currentSize ?? ValueNotifier<double>(initialSize),
availablePixels = double.infinity,
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;

Expand Down Expand Up @@ -590,6 +600,9 @@ class _DraggableSheetExtent {
}

void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_currentSize.dispose();
}

Expand Down
15 changes: 15 additions & 0 deletions packages/flutter/lib/src/widgets/focus_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,18 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier {
// This doesn't extend ChangeNotifier because the callback passes the updated
// value, and ChangeNotifier requires using VoidCallback.
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
// null, no interactions have occurred yet.
bool? _lastInteractionWasTouch;
Expand Down Expand Up @@ -1888,6 +1900,9 @@ class _HighlightModeManager {

@mustCallSuper
void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
if (ServicesBinding.instance.keyEventManager.keyMessageHandler == handleKeyMessage) {
GestureBinding.instance.pointerRouter.removeGlobalRoute(handlePointerEvent);
ServicesBinding.instance.keyEventManager.keyMessageHandler = null;
Expand Down
14 changes: 13 additions & 1 deletion packages/flutter/lib/src/widgets/heroes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,15 @@ class _HeroFlightManifest {
// Builds the in-flight hero widget.
class _HeroFlight {
_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);
}

Expand Down Expand Up @@ -614,6 +623,9 @@ class _HeroFlight {
/// Releases resources.
@mustCallSuper
void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
if (overlayEntry != null) {
overlayEntry!.remove();
overlayEntry!.dispose();
Expand Down Expand Up @@ -1008,7 +1020,7 @@ class HeroController extends NavigatorObserver {
}

void _handleFlightEnded(_HeroFlight flight) {
_flights.remove(flight.manifest.tag);
_flights.remove(flight.manifest.tag)?.dispose();
}

Widget _defaultHeroFlightShuttleBuilder(
Expand Down
12 changes: 12 additions & 0 deletions packages/flutter/lib/src/widgets/nested_scroll_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,15 @@ class _NestedScrollCoordinator implements ScrollActivityDelegate, ScrollHoldCont
this._onHasScrolledBodyChanged,
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;
_outerController = _NestedScrollController(
this,
Expand Down Expand Up @@ -1123,6 +1132,9 @@ class _NestedScrollCoordinator implements ScrollActivityDelegate, ScrollHoldCont

@mustCallSuper
void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_currentDrag?.dispose();
_currentDrag = null;
_outerController.dispose();
Expand Down
6 changes: 6 additions & 0 deletions packages/flutter/lib/src/widgets/overscroll_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ class _GlowController extends ChangeNotifier {
required Axis axis,
}) : _color = color,
_axis = axis {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
_glowController = AnimationController(vsync: vsync)
..addStatusListener(_changePhase);
final Animation<double> decelerator = CurvedAnimation(
Expand Down Expand Up @@ -812,6 +815,9 @@ enum _StretchState {

class _StretchController extends ChangeNotifier {
_StretchController({ required TickerProvider vsync }) {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
_stretchController = AnimationController(vsync: vsync)
..addStatusListener(_changePhase);
final Animation<double> decelerator = CurvedAnimation(
Expand Down
13 changes: 13 additions & 0 deletions packages/flutter/lib/src/widgets/reorderable_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
Expand Down Expand Up @@ -1339,6 +1340,15 @@ class _DragInfo extends Drag {
this.proxyDecorator,
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;
listState = item._listState;
index = item.index;
Expand Down Expand Up @@ -1371,6 +1381,9 @@ class _DragInfo extends Drag {
AnimationController? _proxyAnimation;

void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_proxyAnimation?.dispose();
}

Expand Down
12 changes: 12 additions & 0 deletions packages/flutter/lib/src/widgets/semantics_debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindi

class _SemanticsClient extends ChangeNotifier {
_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(
listener: _didUpdateSemantics,
);
Expand All @@ -191,6 +200,9 @@ class _SemanticsClient extends ChangeNotifier {

@override
void dispose() {
if (kFlutterMemoryAllocationsEnabled) {
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_semanticsHandle!.dispose();
_semanticsHandle = null;
super.dispose();
Expand Down
Loading

0 comments on commit e5f62cc

Please sign in to comment.