-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flatMap keeps its selector alive beyond inner observable completion #2605
flatMap keeps its selector alive beyond inner observable completion #2605
Conversation
This is a bogus test. The flatMap should not complete or free any resources in this use case. Keep in mind, the Observable returned by |
I respectfully disagree, in my opinion resources of the inner observable shouldn't live longer than the subscription to it (which ends with its completion, not with the completion of the observable resulting from flatMap). In the light of your argument, I wonder how #2604 is different. |
If it did, I would have to check if |
@danielt1263 my apologies, the test was indeed bogus, the object should be captured by the inner observable, not by flatMap's closure. I pushed a fix. |
Note that this test, which is more like the Completable test you referenced, passes...
|
@danielt1263 |
@danielt1263 however, getting back to the original test, when the inner one completes, we know that the selector closure will no longer be called, don't we? |
Actually no, we don't know that the selector will no longer be called. If there is a new subscription to the flatMap's Observable, then the |
@danielt1263 yes, but particular subscription's |
The |
@danielt1263 can't subscriptions "shed" no longer necessary pieces, like the selector closure upon inner subscription's completion in this example, is it a design choice? |
I guess it could null out the closure at that point, but that seems like a needless optimization. |
MergeSinkIter
retainsMergeSink
, or to be preciseFlatMapSink
, that retains the selector.It's a bit similar to #2604, however I haven't yet figured out how to address it.
flatMapFirst
andflatMapLast
should be prone to the same issue.