Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c committed Dec 6, 2024
1 parent 3bdbbbd commit 9fcecaf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkgs/leak_tracker/lib/src/leak_tracking/_object_tracker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,7 @@ class ObjectTracker implements LeakProvider {
}

int get notGCed => _objects.notGCed.length;

void forEach(void Function(ObjectRecord) callback) =>
_objects.notGCed.forEach(callback);
}
9 changes: 9 additions & 0 deletions pkgs/leak_tracker/lib/src/leak_tracking/leak_tracking.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '../shared/_primitives.dart';
import '../shared/shared_model.dart';
import '_baseliner.dart';
import '_leak_tracker.dart';
import '_object_record.dart';
import 'primitives/_dispatcher.dart' as dispatcher;
import 'primitives/model.dart';

Expand Down Expand Up @@ -130,6 +131,10 @@ abstract class LeakTracking {
required Object object,
Map<String, dynamic>? context,
}) {
if (object.runtimeType.toString() == 'CkPicture') {
final code = identityHashCode(object);
print('!!! CkPicture created: $code');
}
assert(() {
_baseliner?.takeSample();
if (phase.ignoredLeaks.isIgnored(className)) return true;
Expand Down Expand Up @@ -227,4 +232,8 @@ abstract class LeakTracking {
static void declareNotDisposedObjectsAsLeaks() {
_leakTracker?.objectTracker.declareAllNotDisposedAsLeaks();
}

/// Performs an operation for each object, not detected as GCed.
static void forEach(void Function(ObjectRecord) callback) =>
_leakTracker?.objectTracker.forEach(callback);
}
30 changes: 29 additions & 1 deletion pkgs/web_tests/test/test_infra/memory_leak_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,41 @@ final List<LeakTestCase> memoryLeakTests = <LeakTestCase>[
PumpWidgetsCallback? pumpWidgets,
RunAsyncCallback<dynamic>? runAsync,
) async {
printStats();
await pumpWidgets!(MyApp());
await runAsync!(() => Future.delayed(const Duration(seconds: 3)));

printStats();
await runAsync!(() => Future.delayed(const Duration(seconds: 1)));
printStats();
await runAsync(() => Future.delayed(const Duration(seconds: 1)));
printStats();
await runAsync(() => Future.delayed(const Duration(seconds: 1)));
printStats();
},
notDisposedTotal: 0,
),
];

void printStats() {
final notDisposed = <String, int>{};
LeakTracking.forEach((r) {
if (r.isDisposed) return;
final type = r.type.toString();
if (!type.contains('Picture') && !type.contains('picture')) return;
notDisposed[type] = notDisposed[type] ?? 0 + 1;
});

if (notDisposed.isEmpty) {
print('No not disposed');
return;
}

print('!!!! Not disposed:');
for (final entry in notDisposed.entries) {
print('${entry.key}: ${entry.value}');
}
}

String memoryLeakTestsFilePath() {
final result = RegExp(
r'(\/[^\/]*_tests.dart.js)',
Expand Down

0 comments on commit 9fcecaf

Please sign in to comment.