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 in instance arrays #129

Closed
melgrove opened this issue Jun 4, 2022 · 1 comment · Fixed by #153
Closed

Memory leak in instance arrays #129

melgrove opened this issue Jun 4, 2022 · 1 comment · Fixed by #153

Comments

@melgrove
Copy link
Contributor

melgrove commented Jun 4, 2022

There is a pretty large memory leak when adding multiple instances of Points, Shapes, or Lines.

Reproduce

  1. When points(), shapes(), or lines() is called, it adds a Points, Shapes, or Lines instance to the global pointsInstances, shapesInstances, or linesInstances array. Each instance contains all of the layer information.
  2. When .remove() is called on one the instances (for example: let pointLayer = glify.points({...}); pointLayer.remove()), the instance is not removed from the global instances array. This causes a very large memory leak when rendering and rerendering points many times, since the entire object for every render stays in memory after it has been removed.

A solution

My application must be able to rerender many points many times so I created a workaround. I think that this could be added to the .remove() method, unless I'm missing something.

  1. Store an ID with the instance when creating it:
    let pointLayer = glify.points({...});
    const savedID = generateUniqueID(); // just needs to be unique across the instances
    pointLayer.layerID = savedID;
    
  2. When .remove()ing the instance, also remove it from the instance array manually:
    const instanceIndex = glify.pointsInstances.map(inst => inst.layerID == savedID ? true : false).indexOf(true);
    glify.pointsInstances.splice(instanceIndex, 1);
    
@melgrove
Copy link
Contributor Author

melgrove commented May 2, 2023

It doesn't look like there have been any updates to the package since I created this issue so I don't think so, unless you are referring to something else. I'm probably going to PR a fix and add it to my fork

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.

1 participant