Skip to content

Commit

Permalink
Fix remaining memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit committed Oct 22, 2020
1 parent 7977129 commit 28d105e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/flutter_riverpod/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.12.1

- Fixed an remaining memory leak related to StreamProvider (see also https://github.com/rrousselGit/river_pod/issues/193)

# 0.12.0

- **Breaking** FutureProvider and StreamProvider no-longer supports `null` as a valid value.
Expand Down
4 changes: 4 additions & 0 deletions packages/hooks_riverpod/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.12.1

- Fixed an remaining memory leak related to StreamProvider (see also https://github.com/rrousselGit/river_pod/issues/193)

# 0.12.0

- **Breaking** FutureProvider and StreamProvider no-longer supports `null` as a valid value.
Expand Down
4 changes: 4 additions & 0 deletions packages/riverpod/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.12.1

- Fixed an remaining memory leak related to StreamProvider (see also https://github.com/rrousselGit/river_pod/issues/193)

# 0.12.0

- **Breaking** FutureProvider and StreamProvider no-longer supports `null` as a valid value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AutoDisposeStreamProvider<T>
AutoDisposeStreamProvider(
Create<Stream<T>, AutoDisposeProviderReference> create, {
String name,
}) : super((ref) => create(ref).asBroadcastStream(), name);
}) : super(create, name);

/// {@macro riverpod.family}
static const family = AutoDisposeStreamProviderFamilyBuilder();
Expand Down
26 changes: 26 additions & 0 deletions packages/riverpod/test/framework2/stream_provider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@ void main() {
expect(didCloseSub, true);
});

test('the created stream does not leak on autoDispose providers', () async {
final container = ProviderContainer();
var didCloseSub = false;
final controller = StreamController<int>(
onCancel: () => didCloseSub = true,
);
addTearDown(controller.close);

final provider = StreamProvider.autoDispose((ref) => controller.stream);

var didCloseProxy = false;

final sub = container.listen(provider.stream);
sub.read().listen((_) {}, onDone: () => didCloseProxy = true);

await Future(() {});
expect(didCloseProxy, false);
expect(didCloseSub, false);

container.dispose();
await Future(() {});

expect(didCloseProxy, true);
expect(didCloseSub, true);
});

test('the created stream does not leak on refresh', () async {
final container = ProviderContainer();
var didCloseSub = false;
Expand Down

0 comments on commit 28d105e

Please sign in to comment.