Skip to content
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

MemoryStream dragging memory from previous execution #71

Closed
xtianjohns opened this issue Jul 7, 2016 · 2 comments
Closed

MemoryStream dragging memory from previous execution #71

xtianjohns opened this issue Jul 7, 2016 · 2 comments

Comments

@xtianjohns
Copy link
Contributor

I'm experiencing what seems like odd behavior when working with MemoryStreams and stream completion using xstream.

Consider a stream composed like so:

xs.periodic( 500 ).mapTo( 'world' ).startWith( 'hello' ).take( 2 );

I believe that this stream is a MemoryStream due to the startWith operator. When I add a listener after this stream has completed, the values appear to be emitted in reverse ('world' then 'hello' instead of 'hello' then 'world').

Here is a bin which demonstrates my experience.

I did some sleuthing and considered that since the MemoryStream holds on to the last emitted value, perhaps it was simply holding on to 'world' and then emitting the next known value 'hello', then emitting a maximum of two of those values and terminating. That behavior would make it appear that the stream had somehow been reversed.

Is that behavior expected? I don't really know how to isolate the question further than that - it may not be an issue with MemoryStream, it may be an issue with take, or it may be not an issue at all.

@Hypnosphi
Copy link
Contributor

Hypnosphi commented Jul 7, 2016

Seems like the problem is that cleanup method _x is never called in that case for some reasons. It's definitely a bug. https://github.com/staltz/xstream/blob/master/src/core.ts#L1796-L1799

@staltz staltz changed the title xstream MemoryStream behavior MemoryStream dragging memory from previous execution Jul 8, 2016
@staltz staltz self-assigned this Jul 8, 2016
staltz added a commit that referenced this issue Jul 8, 2016
…ions

Fix MemoryStream to teardown its own internal memory after its execution ends, particularly, when
the last listener is removed and async stop is executed, which is not necessarily the _x() teardown.

Fixes issue #71.
@staltz
Copy link
Owner

staltz commented Jul 8, 2016

Fixed, released in v5.1.4.

Thanks for the careful report @xtianjohns, and thanks for helping out @Hypnosphi.

@staltz staltz closed this as completed Jul 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants