Skip to content

Commit ae8e4d4

Browse files
JakeWhartonakarnokd
authored andcommitted
Free upstream resources when default observer/subscriber is canceled. (#4385)
1 parent 9c38530 commit ae8e4d4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/main/java/io/reactivex/observers/DefaultObserver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public final void onSubscribe(Disposable s) {
3939
*/
4040
protected final void cancel() {
4141
s.dispose();
42+
s = null;
4243
}
4344
/**
4445
* Called once the subscription has been set on this observer; override this

src/main/java/io/reactivex/subscribers/DefaultSubscriber.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ public final void onSubscribe(Subscription s) {
3939
* Requests from the upstream Subscription.
4040
*/
4141
protected final void request(long n) {
42-
s.request(n);
42+
Subscription s = this.s;
43+
if (s != null) {
44+
s.request(n);
45+
}
4346
}
4447

4548
/**
4649
* Cancels the upstream's Subscription.
4750
*/
4851
protected final void cancel() {
4952
s.cancel();
53+
s = null;
5054
}
5155
/**
5256
* Called once the subscription has been set on this observer; override this

0 commit comments

Comments
 (0)