haltu / muuri

Infinite responsive, sortable, filterable and draggable layouts
https://muuri.dev
MIT License
10.77k stars 644 forks source link

Memory Leak? defaultPacker retaining layouts #485

Closed markphilpot closed 3 years ago

markphilpot commented 3 years ago

In my app where we create (and clean up) lots of Grid elements, the static defaultPacker seems to retain every layout (including references to the dom item elements). This seems to result in memory being retained over time.

CleanShot 2021-07-07 at 10 31 03@2x

On reading the code, I can't tell how Grid.defaultPacker._layouts ever gets cleaned up. Do I just to periodically recreate the defaultPacker instance?

niklasramo commented 3 years ago

@markphilpot Actually yes, a memory leak! Good catch 👍

The bug is in this line: https://github.com/haltu/muuri/blob/master/src/Packer/Packer.js#L81.

It should say this instead: if (layout) delete this._layouts[layoutId];

Will fix asap.

niklasramo commented 3 years ago

@markphilpot I created a pull request with a fix here: https://github.com/haltu/muuri/pull/486. Would you mind validating that the fix works in your use case?

markphilpot commented 3 years ago

@markphilpot I created a pull request with a fix here: #486. Would you mind validating that the fix works in your use case?

Yes, the updated delete cleans up the layouts correctly. Looks good 👍

niklasramo commented 3 years ago

This should be now fixed in the latest release: https://github.com/haltu/muuri/releases/tag/0.9.5