instancesOfClass method
Live instances of className after a forced GC (S1r per-class
counter). Counts implementers too — an abstract declared class would
otherwise trivially count 0. Null on RPC failure.
Implementation
Future<int?> instancesOfClass(String className) async {
try {
await _service.getAllocationProfile(_isolateId, gc: true);
final classList = await _service.getClassList(_isolateId);
var total = 0;
for (final c in classList.classes ?? const <vm_service.ClassRef>[]) {
if (c.name == className && c.id != null) {
final set = await _service.getInstances(
_isolateId,
c.id!,
_kInstanceProbeLimit,
includeSubclasses: true,
includeImplementers: true,
);
total += set.totalCount ?? 0;
}
}
return total;
} catch (_) {
return null;
}
}