How would I prevent this from leaking memory?
See original GitHub issuelet 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:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
http://www.html5gamedevs.com/topic/30539-correct-way-to-remove-sprites-container/
and
http://www.html5gamedevs.com/topic/19815-correct-way-of-deleting-a-display-object/
@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!