Closed thgreasi closed 3 years ago
Great catch! Thanks for your help!
@thgreasi
I may have been a little quick to merge this.
The disconnect()
is only supposed to clear all observationTargets
and activeTargets
.
As-is, this PR goes a step further to prevent the ResizeObserver from being used again.
To counter this, we would need to re-add the ResizeObserver to the resizeObservers
list.
I'm going to unpublish v1.0.1, and release a v1.0.2 with this fix in the next couple hours.
As-is, this PR goes a step further to prevent the ResizeObserver from being used again.
@devrelm apologies for not noticing.
To counter this, we would need to re-add the ResizeObserver to the resizeObservers list.
But that would bring back the memory leak b/c the provided callback still being reachable through the ResizeObserver instance in the resizeObservers
list. Perhaps the should be using a WeekSet to avoid this (when available). What do you think?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/WeakSet
No that ^ wouldn't work, b/c you can't enumerate the contents of a WeakSet, which we need here...
@devrelm here is a proper fix for this: https://github.com/pelotoncycle/resize-observer/pull/95
ResizeObserver instances are not eligible for garbage collection since the top level resizeObservers still has a reference to them. As a result whatever was referenced by the callback provided during instantiation, is also not garbage collected.