formattedRetainingPath function
- WeakReference<
Object> ref
Returns nicely formatted retaining path for the WeakReference.target.
If the object is garbage collected or not retained, returns null.
Does not work in web and in release mode.
To run this inside flutter test
pass --enable-vmservice
.
Also does not work for objects that are not returned by getInstances. https://github.com/dart-lang/sdk/blob/3e80d29fd6fec56187d651ce22ea81f1e8732214/runtime/vm/object_graph.cc#L1803
Implementation
Future<String?> formattedRetainingPath(WeakReference ref) async {
if (ref.target == null) return null;
final connection = await connect();
final path = await retainingPath(
connection,
ref.target,
);
if (path == null) return null;
return retainingPathToString(path);
}