Upgrade leak_tracker. (#141153)
This commit is contained in:
committed by
GitHub
parent
51af82d3db
commit
1f3103e50d
@@ -34,14 +34,14 @@ dependencies:
|
||||
vector_math: 2.1.4
|
||||
|
||||
# Used to detect memory leaks with `testWidgets`.
|
||||
leak_tracker_flutter_testing: 2.0.1
|
||||
leak_tracker_flutter_testing: 2.0.3
|
||||
|
||||
async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
leak_tracker: 10.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
leak_tracker_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
leak_tracker: 10.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
leak_tracker_testing: 2.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
@@ -53,4 +53,4 @@ dependencies:
|
||||
dev_dependencies:
|
||||
file: 7.0.0
|
||||
|
||||
# PUBSPEC CHECKSUM: 6913
|
||||
# PUBSPEC CHECKSUM: 3d17
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
|
||||
|
||||
class LeakTrackedClass {
|
||||
LeakTrackedClass() {
|
||||
LeakTracking.dispatchObjectCreated(
|
||||
library: library,
|
||||
className: '$LeakTrackedClass',
|
||||
object: this,
|
||||
);
|
||||
}
|
||||
|
||||
static const String library = 'package:my_package/lib/src/my_lib.dart';
|
||||
|
||||
void dispose() {
|
||||
LeakTracking.dispatchObjectDisposed(object: this);
|
||||
}
|
||||
}
|
||||
|
||||
final List<LeakTrackedClass> _notGCedObjects = <LeakTrackedClass>[];
|
||||
|
||||
class LeakingClass {
|
||||
LeakingClass() {
|
||||
_notGCedObjects.add(LeakTrackedClass()..dispose());
|
||||
}
|
||||
}
|
||||
|
||||
class StatelessLeakingWidget extends StatelessWidget {
|
||||
StatelessLeakingWidget({
|
||||
super.key,
|
||||
this.notGCed = true,
|
||||
this.notDisposed = true,
|
||||
}) {
|
||||
if (notGCed) {
|
||||
_notGCedObjects.add(LeakTrackedClass()..dispose());
|
||||
}
|
||||
if (notDisposed) {
|
||||
// ignore: unused_local_variable, it is unused intentionally, to illustrate not disposed object.
|
||||
final LeakTrackedClass notDisposedObject = LeakTrackedClass();
|
||||
}
|
||||
}
|
||||
|
||||
final bool notGCed;
|
||||
final bool notDisposed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Placeholder();
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
|
||||
|
||||
import 'utils/leaking_classes.dart';
|
||||
|
||||
late final String _test1TrackingOnNoLeaks;
|
||||
late final String _test2TrackingOffLeaks;
|
||||
late final String _test3TrackingOnLeaks;
|
||||
@@ -74,11 +72,11 @@ void main() {
|
||||
);
|
||||
|
||||
testWidgets(_test6TrackingOnNoLeaks = 'test6, tracking-on, no leaks', (_) async {
|
||||
LeakTrackedClass().dispose();
|
||||
InstrumentedDisposable().dispose();
|
||||
});
|
||||
|
||||
testWidgets(_test7TrackingOnNoLeaks = 'test7, tracking-on, tear down, no leaks', (_) async {
|
||||
final LeakTrackedClass myClass = LeakTrackedClass();
|
||||
final InstrumentedDisposable myClass = InstrumentedDisposable();
|
||||
addTearDown(myClass.dispose);
|
||||
});
|
||||
|
||||
@@ -86,7 +84,7 @@ void main() {
|
||||
expect(LeakTracking.isStarted, true);
|
||||
expect(LeakTracking.phase.name, _test8TrackingOnNotDisposed);
|
||||
expect(LeakTracking.phase.ignoreLeaks, false);
|
||||
LeakTrackedClass();
|
||||
InstrumentedDisposable();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -196,7 +194,7 @@ void _verifyLeakList(
|
||||
expect(list.length, expectedCount, reason: testDescription);
|
||||
|
||||
for (final LeakReport leak in list) {
|
||||
expect(leak.trackedClass, contains(LeakTrackedClass.library));
|
||||
expect(leak.trackedClass, contains('$LeakTrackedClass'));
|
||||
expect(leak.trackedClass, contains(InstrumentedDisposable.library));
|
||||
expect(leak.trackedClass, contains('$InstrumentedDisposable'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user