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

Removing a child observable #71

Open
ffreyer opened this issue Apr 24, 2021 · 1 comment
Open

Removing a child observable #71

ffreyer opened this issue Apr 24, 2021 · 1 comment
Milestone

Comments

@ffreyer
Copy link
Contributor

ffreyer commented Apr 24, 2021

As far as I can tell there is no automatic way to remove a child observable and detach it from all its parents. For example

O1 = Observable(1)
O2 = map(identity, O1)
O2 = nothing
GC.gc()

will leave you with a listener in O1 and O2 will remain somewhere in memory. The same happens with weak = true - the mapped observable and the listeners remain. In these cases one can explicitly remove listener with off.(O2.inputs), which then allows them to be gced.

With on it's a bit different. There are no references being kept in inputs for on, so the above doesn't work. The gc will also happily remove the observable when it goes out of scope, causing this to error:

O1 = Observable(1)
O2 = Observable(1)
on(x -> O2[] = x, O1)
O2 = nothing
O1[] = 1

So in this case one would need to keep track of observer functions themselves to correctly remove a child. It would be nice if this was easier to handle.

@timholy timholy added this to the 1.0 milestone Oct 9, 2021
@timholy
Copy link
Member

timholy commented Oct 9, 2021

xref #69. I don't currently have the bandwidth to tackle this but it's probably the one remaining big issue for this package to address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants