jdonaldson / promhx

A promise and functional reactive programming library for Haxe
MIT License
145 stars 24 forks source link

Memory leak? #57

Closed andyli closed 9 years ago

andyli commented 9 years ago

The implementation of Stream#first() looks like a memory leak to me, in the sense that the returned Promise can never be freed since it subscribes to the stream update forever.

In general, is there a way to unsubscribe?

jdonaldson commented 9 years ago

It's possible to unbind a stream, but it's not currently possible for a promise.

Keeping a promise bound is pretty useful, as it helps to catch situations where a promise resolves more than once (which can cause a lot of undesirable behavior, or expose a flaw in how you were trying to use the promise). This can only work if the promise maintains a connection to its upstream resolver.

However, for practical purposes I do agree that it's useful to clear the memory after some point. I think I'll relax some of the constraints on Stream.detachStream so it can work with promises.

jdonaldson commented 9 years ago

In the future, you can use :

some_async.unlink(some_other_async);

This will unlink the two asyncs. Note that this operation (like the other link method) is asynchronous.

jdonaldson commented 9 years ago

also note, the use of unlink is not really recommended.