-
Notifications
You must be signed in to change notification settings - Fork 255
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
Release ReferenceCounted when timer expires. #314
Conversation
This changeset subscribes when the "no subscriber" timer fires and if the item is actually a reference counted item, completely releases it and prevents it from leaking out of the pool.
fixes #311 |
@@ -138,7 +137,14 @@ private UnicastContentSubject(final State<T> state, long noSubscriptionTimeout, | |||
*/ | |||
public boolean disposeIfNotSubscribed() { | |||
if (state.casState(State.STATES.UNSUBSCRIBED, State.STATES.DISPOSED)) { | |||
state.bufferedSubject.subscribe(Subscribers.empty()); // Drain all items so that ByteBuf gets released. | |||
state.bufferedSubject.subscribe(new Action1<T>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make it safer for future issues like this, I think it will be better to split the subject into an Observable
and Observer
with Observable
always wired with auto-release. Something like:
private final Observer<T> bufferedObserver;
private final Observable<T> bufferedObservable;
public State(Action0 onUnsubscribe) {
this.onUnsubscribe = onUnsubscribe;
final BufferUntilSubscriber<T> bufferedSubject = BufferUntilSubscriber.create();
bufferedObservable = bufferedSubject.lift(new AutoReleaseByteBufOperator<T>());
bufferedObserver = bufferedSubject;
}
and then we do not store the Subject
variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I'll try to modify it
Thanks @daschl for the fix. Let me know what your views are on my comments. |
Great! Will make the changes. Btw, we also should unsubscribe from the timer when a subscrption comes along, right? |
Yes, that will remove the redundant tick from the scheduler. Makes sense. |
@daschl ping, are you working on this? I would like to fix this before I do a release for 0.4.5 |
@NiteshKant I can revisit it this week hopefully, but I'm a little dragged into something else. So if you want to pick it up and drag it over the finish line please go ahead :) |
Yep, lemme do that. Thanks! |
Closing this in favor of PR #320 |
This changeset subscribes when the "no subscriber" timer fires and
if the item is actually a reference counted item, completely releases
it and prevents it from leaking out of the pool.