BoundedReplayBuffer no longer leaks memory by AttwellBrian · Pull Request #5282 · ReactiveX/RxJava (original) (raw)
I've thought about this and the problem with the change is that now there are two Node allocations happening per item instead of one. I would accept such change if it happened when the terminal events are received; the head no longer references +1 item for an unknown duration.
Doesn't sound like a significant improvement. I can't think of any improvement ideas for this. Can you?
Why is this extra 1 item causing you trouble?
While Rx is designed with immutable value objects in mind, it is useful for asynchronously emitting other types as well. For example, passing around an Observable<MapUI>
instead of a MapUI
inside the Uber app makes it easy to continue progressing application startup while waiting for the map to load.
Optimizations like this have a large affect on application startup time. However, if something in Rx leaks MapUI
we're in trouble! This will leak the entire app's Activity
.
There are a bunch of operators having the same replay like behavior implemented with the same node logic
Interesting. I see this was true with Rx1 as well. So I guess this leak isn't a huge deal. It hasn't caused many issues for us in the last two years.
My takeaway is: never put objects you don't want leaked into rx caches because the cache may live longer than expected.