Skip to content

How best to release elements in a ReplaySubject? #1794

@simonbasle

Description

@simonbasle

Hi,

We're using ReplaySubject to keep a streamed response from a server into a buffer, in order to be able to pass the whole (finite) sequence to observables that subscribe to the subject.

The whole sequence may take a bit of time to complete, but we want to pass the Observable right away to client code.Furthermore, client code may not immediately subscribe to the flow, or it could subscribe several time to do multiple processing of the sequence.

Thus the use of ReplaySubject to avoid replaying the original request each time, and to avoid blocking for the server to respond with the whole sequence.

However, said elements are resources that are reference counted and should be manually freed before being garbage collected. What do you think is the best approach to cope with that?

Maybe what we need is to add semantics on the ReplaySubject to do cleanup and clear the buffer (like a dispose() or release() method)? This would probably also be needed in the bounded ReplaySubject to plug in cleanup behavior at eviction time...

Maybe there is a better alternative to ReplaySubject? Or a simple solution like foreaching on the items and cleaning them up this way?

I hope someone will be able to make a suggestion, and I'd be delighted to contribute if it makes sense ;) Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions