topClasses method

Future<List<(String, int)>> topClasses({
  1. int limit = 30,
})

Top retained Dart classes by bytes (after a forced GC) — the "where did the heap delta go" breakdown. Returns (name, bytes) pairs, most bytes first, or an empty list when the profile is unavailable.

Implementation

Future<List<(String, int)>> topClasses({int limit = 30}) async {
  try {
    final profile = await _service.getAllocationProfile(
      _isolateId,
      gc: true,
    );
    final rows = <(String, int)>[
      for (final c in profile.members ?? const <vm_service.ClassHeapStats>[])
        if ((c.bytesCurrent ?? 0) > 0)
          (c.classRef?.name ?? '?', c.bytesCurrent!),
    ]..sort((a, b) => b.$2.compareTo(a.$2));
    return rows.take(limit).toList();
  } catch (_) {
    return const [];
  }
}