Alpine: MutationObserver is never disconnect

Created on 2 May 2020  路  8Comments  路  Source: alpinejs/alpine

Hi there

I have noticed that MutationObserver is never disconnected, which in most cases result in the terrible memory performance. Are you planning to address that in the near future? What are your thoughts on that?

Most helpful comment

From MDN::disconnect

If the element being observed is removed from the DOM and then subsequently released by the browser's garbage collection mechanism, the MutationObserver is likewise deleted.

So it shouldn't be needed to manually disconnect.

All 8 comments

Do you have an example to replicate the issue? Can you provide more details please? Thanks

Its in the SRC/index.js.
Find MutationObserver instance. It's there.

yeah, I know where the mutation observer is.
I wonder if you have an example of where it would be an issue.
It's an object so it stays in memory as long as it's referenced by the page like other objects, right?
Have you experienced slowness or other stuff? Do you have any concerns you can explain?Alternatives to provide? etc.
Otherwise it's not clear what the issue refers to so it's hard to understand if it requires a fix or not.
Thanks

P.s. the mutation observer need to run continuously because it's how the author designed the library. it will intercept new elements added to the DOM and instantiate their reactivity.
When you navigate to a different page, the garbage collector will eventually trash the object.

I don't have a concrete example, no. I was just addressing the fact that if the object does not get disconnected, it can cause the issue.
I hope that you understand my concern which is the point of opening this issue.

From MDN::disconnect

If the element being observed is removed from the DOM and then subsequently released by the browser's garbage collection mechanism, the MutationObserver is likewise deleted.

So it shouldn't be needed to manually disconnect.

Thanks @var-che @mblarsen

Are we good to close this issue? Doesn't sound like there's a concrete bug or reproduction case mentioned.

Closing this for now, feel free to reopen if it's actually causing a reproducible issue 馃槃 thanks for the discussion everyone.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aolko picture aolko  路  5Comments

imliam picture imliam  路  5Comments

mikemartin picture mikemartin  路  3Comments

bep picture bep  路  4Comments

allmarkedup picture allmarkedup  路  4Comments