Skip to main content

dispose-provided-instances

added in: 1.19.0
Pro+

Warns when an instance with a dispose method created inside a provider does not have the dispose method called in ref.onDispose.

Not disposing such instances may lead to memory leaks and should be avoided.

Example

❌ Bad:

Provider.autoDispose((ref) {
final instance = DisposableService(); // LINT

return instance;
});

class DisposableService {
void dispose() {}
}

✅ Good:

Provider.autoDispose((ref) {
final instance = DisposableService();

ref.onDispose(instance.dispose);

return instance;
});

class DisposableService {
void dispose() {}
}