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

Debugging potential leaks #216

Closed
dbashford opened this issue Dec 16, 2019 · 1 comment · Fixed by #217
Closed

Debugging potential leaks #216

dbashford opened this issue Dec 16, 2019 · 1 comment · Fixed by #217

Comments

@dbashford
Copy link
Contributor

dbashford commented Dec 16, 2019

I'm debugging some leak issues we have using ember-in-viewport. While I haven't got to the source just yet, I did notice this...

In the in-viewport service, you have a startIntersectionObserver function which instantiates an ObserverAdmin (code).

startIntersectionObserver() {
  this.observerAdmin = new ObserverAdmin();
}

In the in-viewport service's watchElement function (code), you protect the creation of observerAdmin, making sure you don't create if you already have one.

watchElement(element, configOptions = {}, enterCallback, exitCallback) {
  if (get(this, 'viewportUseIntersectionObserver')) {
    if (!get(this, 'observerAdmin')) {
      this.startIntersectionObserver();
    }
    ...

However, in the _setInitialViewport function of the in-viewport mixin (code) you call startIntersectionObserver without such a protection.

  _setInitialViewport(element) {
    const isTearingDown = this.isDestroyed || this.isDestroying;
    if (!element || isTearingDown) {
      return;
    }

    const inViewport = get(this, 'inViewport');

    if (get(this, 'viewportUseIntersectionObserver')) {
      inViewport.startIntersectionObserver();
      ...

I'm not positive that this is the cause of our leaks, but the loss/overwrite of the observer admin reference, which holds the registry that IS our leak, is making it hard to make any sort of fix.

Assuming this is the problem I think it might be, the right solution here might be to protect creation of observerAdmin inside startIntersectionObserver rather than its callers. I've made that locally while I debug things.

Happy to PR that in, but to be honest, I've been debugging a straight line to the leak and I've ignored some of what I've debugged through, so I may be missing a reason for re-creation of the observerAdmin

@snewcomer
Copy link
Collaborator

snewcomer commented Dec 17, 2019

@dbashford 👋 I believe you are right! We may need to remove this line. What do you think? If so, a PR is welcome!

https://github.com/DockYard/ember-in-viewport/blob/master/addon/mixins/in-viewport.js#L125

Also, for future reference, the Mixin will surely be deprecated in the future. The service is the recommended path forward just in case I haven't stated it in the README.

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

Successfully merging a pull request may close this issue.

2 participants