How to write a reliable ref counting test:
ReferenceTracker. Alternatively, arc_test and ref_count_test use a int32_t* counter pattern, but the idea is the same. Rather than checking the actual ref counts, these patterns just watch for when the destructor is called.@pragma('vm:never-inline').expect(object, isNotNull) to ensure that object stays alive until then.doGC() to force run GC. If you‘re on a platform that doesn’t support doGC() (ie canDoGC is false), use flutterDoGC() (though it's slower, not 100% reliable, and breaks autorelease pools, so should be avoided).await Future<void>.delayed(Duration.zero) to allow the disposal message to be sent back to the owner isolate so that the registered closure is cleaned up. After that you'll need to call doGC() again to make sure the closure is destroyed.blockHasRegisteredClosure to test that the closure is destroyed.objc_autoreleasePoolPush/Pop. Make sure not to do any async/await stuff in between the push and pop.