Skip to content

Commit e5f62cc

Browse files
authored
Private disposables should dispatch creation and disposal events. (#141535)
1 parent 1a2c315 commit e5f62cc

15 files changed

+187
-9
lines changed

packages/flutter/lib/src/material/mergeable_material.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'dart:ui' show lerpDouble;
66

7+
import 'package:flutter/foundation.dart';
78
import 'package:flutter/rendering.dart';
89
import 'package:flutter/widgets.dart';
910

@@ -147,7 +148,17 @@ class _AnimationTuple {
147148
required this.startAnimation,
148149
required this.endAnimation,
149150
required this.gapAnimation,
150-
});
151+
}) {
152+
// TODO(polina-c): stop duplicating code across disposables
153+
// https://github.com/flutter/flutter/issues/137435
154+
if (kFlutterMemoryAllocationsEnabled) {
155+
FlutterMemoryAllocations.instance.dispatchObjectCreated(
156+
library: 'package:flutter/material.dart',
157+
className: '$_AnimationTuple',
158+
object: this,
159+
);
160+
}
161+
}
151162

152163
final AnimationController controller;
153164
final CurvedAnimation startAnimation;
@@ -157,6 +168,9 @@ class _AnimationTuple {
157168

158169
@mustCallSuper
159170
void dispose() {
171+
if (kFlutterMemoryAllocationsEnabled) {
172+
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
173+
}
160174
controller.dispose();
161175
startAnimation.dispose();
162176
endAnimation.dispose();

packages/flutter/lib/src/material/tabs.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,15 @@ class _IndicatorPainter extends CustomPainter {
437437
this.dividerHeight,
438438
required this.showDivider,
439439
}) : super(repaint: controller.animation) {
440+
// TODO(polina-c): stop duplicating code across disposables
441+
// https://github.com/flutter/flutter/issues/137435
442+
if (kFlutterMemoryAllocationsEnabled) {
443+
FlutterMemoryAllocations.instance.dispatchObjectCreated(
444+
library: 'package:flutter/material.dart',
445+
className: '$_IndicatorPainter',
446+
object: this,
447+
);
448+
}
440449
if (old != null) {
441450
saveTabOffsets(old._currentTabOffsets, old._currentTextDirection);
442451
}
@@ -466,6 +475,9 @@ class _IndicatorPainter extends CustomPainter {
466475
}
467476

468477
void dispose() {
478+
if (kFlutterMemoryAllocationsEnabled) {
479+
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
480+
}
469481
_painter?.dispose();
470482
}
471483

packages/flutter/lib/src/material/time_picker.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:async';
66
import 'dart:math' as math;
77
import 'dart:ui';
88

9+
import 'package:flutter/foundation.dart';
910
import 'package:flutter/rendering.dart';
1011
import 'package:flutter/services.dart';
1112
import 'package:flutter/widgets.dart';
@@ -904,7 +905,17 @@ class _DialPainter extends CustomPainter {
904905
required this.radius,
905906
required this.textDirection,
906907
required this.selectedValue,
907-
}) : super(repaint: PaintingBinding.instance.systemFonts);
908+
}) : super(repaint: PaintingBinding.instance.systemFonts) {
909+
// TODO(polina-c): stop duplicating code across disposables
910+
// https://github.com/flutter/flutter/issues/137435
911+
if (kFlutterMemoryAllocationsEnabled) {
912+
FlutterMemoryAllocations.instance.dispatchObjectCreated(
913+
library: 'package:flutter/material.dart',
914+
className: '$_DialPainter',
915+
object: this,
916+
);
917+
}
918+
}
908919

909920
final List<_TappableLabel> primaryLabels;
910921
final List<_TappableLabel> selectedLabels;
@@ -920,6 +931,9 @@ class _DialPainter extends CustomPainter {
920931
final int selectedValue;
921932

922933
void dispose() {
934+
if (kFlutterMemoryAllocationsEnabled) {
935+
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
936+
}
923937
for (final _TappableLabel label in primaryLabels) {
924938
label.painter.dispose();
925939
}

packages/flutter/lib/src/painting/decoration_image.dart

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,17 @@ abstract interface class DecorationImagePainter {
311311
}
312312

313313
class _DecorationImagePainter implements DecorationImagePainter {
314-
_DecorationImagePainter._(this._details, this._onChanged);
314+
_DecorationImagePainter._(this._details, this._onChanged) {
315+
// TODO(polina-c): stop duplicating code across disposables
316+
// https://github.com/flutter/flutter/issues/137435
317+
if (kFlutterMemoryAllocationsEnabled) {
318+
FlutterMemoryAllocations.instance.dispatchObjectCreated(
319+
library: 'package:flutter/painting.dart',
320+
className: '$_DecorationImagePainter',
321+
object: this,
322+
);
323+
}
324+
}
315325

316326
final DecorationImage _details;
317327
final VoidCallback _onChanged;
@@ -404,6 +414,9 @@ class _DecorationImagePainter implements DecorationImagePainter {
404414

405415
@override
406416
void dispose() {
417+
if (kFlutterMemoryAllocationsEnabled) {
418+
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
419+
}
407420
_imageStream?.removeListener(ImageStreamListener(
408421
_handleImage,
409422
onError: _details.onError,
@@ -801,7 +814,17 @@ class _BlendedDecorationImage implements DecorationImage {
801814
}
802815

803816
class _BlendedDecorationImagePainter implements DecorationImagePainter {
804-
_BlendedDecorationImagePainter._(this.a, this.b, this.t);
817+
_BlendedDecorationImagePainter._(this.a, this.b, this.t) {
818+
// TODO(polina-c): stop duplicating code across disposables
819+
// https://github.com/flutter/flutter/issues/137435
820+
if (kFlutterMemoryAllocationsEnabled) {
821+
FlutterMemoryAllocations.instance.dispatchObjectCreated(
822+
library: 'package:flutter/painting.dart',
823+
className: '$_BlendedDecorationImagePainter',
824+
object: this,
825+
);
826+
}
827+
}
805828

806829
final DecorationImagePainter? a;
807830
final DecorationImagePainter? b;
@@ -817,6 +840,9 @@ class _BlendedDecorationImagePainter implements DecorationImagePainter {
817840

818841
@override
819842
void dispose() {
843+
if (kFlutterMemoryAllocationsEnabled) {
844+
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
845+
}
820846
a?.dispose();
821847
b?.dispose();
822848
}

packages/flutter/lib/src/painting/image_cache.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,17 @@ abstract class _CachedImageBase {
606606
_CachedImageBase(
607607
this.completer, {
608608
this.sizeBytes,
609-
}) : handle = completer.keepAlive();
609+
}) : handle = completer.keepAlive() {
610+
// TODO(polina-c): stop duplicating code across disposables
611+
// https://github.com/flutter/flutter/issues/137435
612+
if (kFlutterMemoryAllocationsEnabled) {
613+
FlutterMemoryAllocations.instance.dispatchObjectCreated(
614+
library: 'package:flutter/painting.dart',
615+
className: '$_CachedImageBase',
616+
object: this,
617+
);
618+
}
619+
}
610620

611621
final ImageStreamCompleter completer;
612622
int? sizeBytes;
@@ -615,6 +625,9 @@ abstract class _CachedImageBase {
615625
@mustCallSuper
616626
void dispose() {
617627
assert(handle != null);
628+
if (kFlutterMemoryAllocationsEnabled) {
629+
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
630+
}
618631
// Give any interested parties a chance to listen to the stream before we
619632
// potentially dispose it.
620633
SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) {

packages/flutter/lib/src/rendering/binding.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@ class RenderingFlutterBinding extends BindingBase with GestureBinding, Scheduler
754754
/// A [PipelineManifold] implementation that is backed by the [RendererBinding].
755755
class _BindingPipelineManifold extends ChangeNotifier implements PipelineManifold {
756756
_BindingPipelineManifold(this._binding) {
757+
if (kFlutterMemoryAllocationsEnabled) {
758+
ChangeNotifier.maybeDispatchObjectCreation(this);
759+
}
757760
_binding.addSemanticsEnabledListener(notifyListeners);
758761
}
759762

packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,17 @@ class _DraggableSheetExtent {
494494
_currentSize = currentSize ?? ValueNotifier<double>(initialSize),
495495
availablePixels = double.infinity,
496496
hasDragged = hasDragged ?? false,
497-
hasChanged = hasChanged ?? false;
497+
hasChanged = hasChanged ?? false {
498+
// TODO(polina-c): stop duplicating code across disposables
499+
// https://github.com/flutter/flutter/issues/137435
500+
if (kFlutterMemoryAllocationsEnabled) {
501+
FlutterMemoryAllocations.instance.dispatchObjectCreated(
502+
library: 'package:flutter/widgets.dart',
503+
className: '$_DraggableSheetExtent',
504+
object: this,
505+
);
506+
}
507+
}
498508

499509
VoidCallback? _cancelActivity;
500510

@@ -590,6 +600,9 @@ class _DraggableSheetExtent {
590600
}
591601

592602
void dispose() {
603+
if (kFlutterMemoryAllocationsEnabled) {
604+
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
605+
}
593606
_currentSize.dispose();
594607
}
595608

packages/flutter/lib/src/widgets/focus_manager.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,18 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier {
18311831
// This doesn't extend ChangeNotifier because the callback passes the updated
18321832
// value, and ChangeNotifier requires using VoidCallback.
18331833
class _HighlightModeManager {
1834+
_HighlightModeManager() {
1835+
// TODO(polina-c): stop duplicating code across disposables
1836+
// https://github.com/flutter/flutter/issues/137435
1837+
if (kFlutterMemoryAllocationsEnabled) {
1838+
FlutterMemoryAllocations.instance.dispatchObjectCreated(
1839+
library: 'package:flutter/widgets.dart',
1840+
className: '$_HighlightModeManager',
1841+
object: this,
1842+
);
1843+
}
1844+
}
1845+
18341846
// If set, indicates if the last interaction detected was touch or not. If
18351847
// null, no interactions have occurred yet.
18361848
bool? _lastInteractionWasTouch;
@@ -1888,6 +1900,9 @@ class _HighlightModeManager {
18881900

18891901
@mustCallSuper
18901902
void dispose() {
1903+
if (kFlutterMemoryAllocationsEnabled) {
1904+
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
1905+
}
18911906
if (ServicesBinding.instance.keyEventManager.keyMessageHandler == handleKeyMessage) {
18921907
GestureBinding.instance.pointerRouter.removeGlobalRoute(handlePointerEvent);
18931908
ServicesBinding.instance.keyEventManager.keyMessageHandler = null;

packages/flutter/lib/src/widgets/heroes.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,15 @@ class _HeroFlightManifest {
510510
// Builds the in-flight hero widget.
511511
class _HeroFlight {
512512
_HeroFlight(this.onFlightEnded) {
513+
// TODO(polina-c): stop duplicating code across disposables
514+
// https://github.com/flutter/flutter/issues/137435
515+
if (kFlutterMemoryAllocationsEnabled) {
516+
FlutterMemoryAllocations.instance.dispatchObjectCreated(
517+
library: 'package:flutter/widgets.dart',
518+
className: '$_HeroFlight',
519+
object: this,
520+
);
521+
}
513522
_proxyAnimation = ProxyAnimation()..addStatusListener(_handleAnimationUpdate);
514523
}
515524

@@ -614,6 +623,9 @@ class _HeroFlight {
614623
/// Releases resources.
615624
@mustCallSuper
616625
void dispose() {
626+
if (kFlutterMemoryAllocationsEnabled) {
627+
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
628+
}
617629
if (overlayEntry != null) {
618630
overlayEntry!.remove();
619631
overlayEntry!.dispose();
@@ -1008,7 +1020,7 @@ class HeroController extends NavigatorObserver {
10081020
}
10091021

10101022
void _handleFlightEnded(_HeroFlight flight) {
1011-
_flights.remove(flight.manifest.tag);
1023+
_flights.remove(flight.manifest.tag)?.dispose();
10121024
}
10131025

10141026
Widget _defaultHeroFlightShuttleBuilder(

packages/flutter/lib/src/widgets/nested_scroll_view.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,15 @@ class _NestedScrollCoordinator implements ScrollActivityDelegate, ScrollHoldCont
596596
this._onHasScrolledBodyChanged,
597597
this._floatHeaderSlivers,
598598
) {
599+
// TODO(polina-c): stop duplicating code across disposables
600+
// https://github.com/flutter/flutter/issues/137435
601+
if (kFlutterMemoryAllocationsEnabled) {
602+
FlutterMemoryAllocations.instance.dispatchObjectCreated(
603+
library: 'package:flutter/widgets.dart',
604+
className: '$_NestedScrollCoordinator',
605+
object: this,
606+
);
607+
}
599608
final double initialScrollOffset = _parent?.initialScrollOffset ?? 0.0;
600609
_outerController = _NestedScrollController(
601610
this,
@@ -1123,6 +1132,9 @@ class _NestedScrollCoordinator implements ScrollActivityDelegate, ScrollHoldCont
11231132

11241133
@mustCallSuper
11251134
void dispose() {
1135+
if (kFlutterMemoryAllocationsEnabled) {
1136+
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
1137+
}
11261138
_currentDrag?.dispose();
11271139
_currentDrag = null;
11281140
_outerController.dispose();

0 commit comments

Comments
 (0)