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 leak with slot > repeat #310

Closed
zakjan opened this issue Oct 1, 2017 · 8 comments
Closed

Memory leak with slot > repeat #310

zakjan opened this issue Oct 1, 2017 · 8 comments

Comments

@zakjan
Copy link

zakjan commented Oct 1, 2017

I'm submitting a bug report

  • Library Version:
    1.4.0

Please tell us about your environment:

  • Operating System:
    OSX 10.x

  • Browser:
    Chrome 62.0.3202.29

Current behavior:
When repeat.for is used in slot content, updating the iterated collection causes memory leaks. It doesn't release unused custom elements from previous collection items.

  <container>
    <template repeat.for="item of items">
      <item item.bind="item"></item>
    </template>
  </container>

Steps to reproduce:

  1. open https://gist.run/?id=5c2d55c58bb270bfab2f41026898cd23
  2. take a heap snapshot, filter objects by Item -> found 5x
  3. click Reset items button
  4. force GC
  5. take a heap snapshot, filter objects by Item -> found 10x

Expected/desired behavior:

  • What is the expected behavior?
    All custom elements should be GC'ed when not displayed. Step 3) should return 5 Item objects only.

  • What is the motivation / use case for changing the behavior?
    Prevent memory leaks in long-running SPA when the iterated collection changes.

@zakjan
Copy link
Author

zakjan commented Oct 1, 2017

Probably related to #265, a dummy div between slot and repeat fixes it. Such div may be undesirable because of page layout.

@zakjan zakjan changed the title Memory leak with repeat + slot Memory leak with slot > repeat Oct 1, 2017
@andlebed
Copy link

andlebed commented Apr 5, 2018

I also noticed that all lifecycle hooks are triggered except unbind.

@bigopon
Copy link
Member

bigopon commented Jun 20, 2018

@EisenbergEffect Fixed by aurelia/templating#592

@rbakhshi
Copy link

rbakhshi commented Jul 20, 2018

That commit didn't fix this problem. But the workaround works fine (wrap the repeat in a div)

@hdplampert
Copy link

Another reproduction here:
https://gist.run/?id=2626ec6901e7876c586edada483e4f99
Click on Add, then Remove. Take a heap snapshot after forcing garbage collection. Look for objects with constructor Item.

It looks like ShadowSlot is keeping references to it's children but never disposing of them.
Removing those references on ShadowSlot.removeView appears to solve the leak, but I'm not sure if it is the correct approach.

@bigopon
Copy link
Member

bigopon commented Sep 29, 2018

@hdplampert I don't think the gist is running on latest version of Aurelia. Can you try again with this https://codesandbox.io/s/9zzq38mn94

@bigopon
Copy link
Member

bigopon commented Mar 21, 2019

Fixed by aurelia/templating#637

Please help file new issue if the problem still persists for you.

@bigopon bigopon closed this as completed Mar 21, 2019
@thomas-darling
Copy link

@EisenbergEffect @bigopon
This bug is still very much still alive! 🐛

I've opened a new issue here: #392

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

6 participants