question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How would I prevent this from leaking memory?

See original GitHub issue
let g = hexi(1000, 1000, setup);
g.border = "2px red dashed";
g.backgroundColor = 0x000000;
g.scaleToWindow();
g.start();

var scene, tiles;

function setup() {
    g.state = play;
    scene = g.group();

    tiles = [];
    for(i = 0; i < 20; i++) {
        var row = [];
        for(j = 0; j < 20; j++) {
            var color = (i + j) % 2 == 0 ? "#ffffff" : "#000000";
            var tile = g.rectangle(50, 50, color, null, 0, 50*i, 50*j);
            row.push(tile);
            scene.add(tile);
        }
        tiles.push(row);
    }

    index = 0;
}

var index;

function setTileColor(x, y, color) {
    scene.removeChild(tiles[index][index]);
    tiles[index][index] = g.rectangle(50, 50, color, "#000000", 0, 50*index, 50*index);
}

function play(){
    for(i = 0; i < 100; i++) setTileColor(0, 0, "#ff0000");
}

The play function is obviously just for testing, but if you run this for a couple of seconds you can see firefox’s memory usage rising dramatically. So my question is how do I prevent this code from leaking memory?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

0reactions
kittykatattackcommented, Sep 9, 2017

@SuperCuber: No problem - my guess is that the memory usage is normal (?) so there’s probably no need to do any testing. If anyone else would like to comment on this, please do!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Memory Leak? How can we avoid? - GeeksforGeeks
To avoid memory leaks, memory allocated on heap should always be freed when no longer needed. C. C ...
Read more >
How To Detect and Prevent Memory Leaks | Scout APM Blog
The memory leak, in this case, can be fixed by nullifying originalThing at the end of the replaceThing function. Such cases can also...
Read more >
Memory leak detection - How to find, eliminate, and avoid
Another important way to prevent memory leaks is to write code which disposes of unneeded resources. Nearly all languages include resource types ...
Read more >
Java Memory Leaks: Solutions, Tools, Tutorials & More - Stackify
1. Use reference objects to avoid memory leaks · SoftReference object: garbage collector is required to clear all SoftReference objects when ...
Read more >
How do I check for memory leaks, and what should I do to stop ...
To find a memory leak, you've got to look at the system's RAM usage. This can be accomplished in Windows by using the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found