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

Memory Leaks #1

Open
yorrd opened this issue Apr 1, 2019 · 6 comments
Open

Memory Leaks #1

yorrd opened this issue Apr 1, 2019 · 6 comments

Comments

@yorrd
Copy link

yorrd commented Apr 1, 2019

You're subscribing to observables, but they're not being unsubscribed when the part is removed. Doesn't this create memory leaks?

@Dabolus
Copy link
Owner

Dabolus commented Apr 9, 2019

@yorrd yes, definitely. This will be fixed when (if) we get a disconnected handler for directives. Besides that, I just noticed that there is also a memory leak when an observable gets replaced with another, since the old observables aren't currently being unsubscribed. I'm going to fix it in the next couple of days.

@yorrd
Copy link
Author

yorrd commented Apr 9, 2019

@Dabolus great. I'm active in that issue as well, was just wondering if you knew of that. Looking forward to where this is going. Currently, we solve the memory leak issues by extending lit-html with unmount handlers. That's not abstracted away though atm, one part is monkey-patched because the respective API is not public

@tyroneneill
Copy link

@Dabolus @yorrd while we wait for the handlers to be implemented in the next version of lit-html I think we can safely handle this ourselves.

I have had a go at it here, have not added any test coverage yet but can confirm the destroy hooks are activated if we remove the bound dom element.

It does come with a trade-off in that the custom element needs to use a corresponding mixin:

@customElement('my-element')
export class MyElement extends LifecycleMixin(LitElement) {
   ...
}

I don't really want to create/manage a library (lazy) and thinking maybe I could raise a PR against lit-rx?

@yorrd
Copy link
Author

yorrd commented Jan 8, 2021

@tyroneneill I've implemented this in our stack, but it's very deep inside and not well abstracted away. Looking forward to lit 3.0 to finally fix this the right way

@klauss194
Copy link

hey guys, was curious if there is any update on this matter
I'm loving Rx so far. was thinking how would an Rx & lit app look like ?

@yorrd
Copy link
Author

yorrd commented Dec 15, 2023

@klauss194 at the moment, we're using a custom controller (we call it RXController) that subscribes and unsubscribes on connect / disconnect. You pass an observable and the value is exposed via .value. With the new lit versions, this is pretty straight forward.

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

4 participants