Observer API memory usage

Viewed 87

there is an example on the MDN document.

function createObserver() {
  let observer;

  let options = {
    root: null,
    rootMargin: "0px",
    threshold: buildThresholdList()
  };

  observer = new IntersectionObserver(handleIntersect, options);
  observer.observe(boxElement);
}

I am wondering when is the observer object would be free by the GC.

Because there is no variable access to observer after function is end.But this example still functional.

Can memory usage be seem in chrome dev-tool ?

Thank for any help !!

1 Answers

You can see chrome memory usage in the "memory" tab...

As for when it is GC. It will be collected only once it is destroyed. It is because the callback could have side-effects.

Related