Page 1 of 1

Memory is not getting free'd

Posted: Sun Apr 06, 2014 2:31 pm
by nuno
Hi everyone,

I'm not sure if I'm doing something wrong or if this is how it's supposed to be.
I was experimenting loading a big image, and then loading a different one into the same variable. I expected that the memory stayed about the same, but it increased. If i repeat the process, even with the same image, the memory goes on increasing forever.

I made this short piece of code to illustrate this: http://hastebin.com/yororoxoyu.lua
Even by setting the var to nil, the memory doesn't get lower.
If I keep repeating it, eventually the game and love crash when the memory usage reaches 100%.

In this example I used ImageData just to make sure the problem wasn't only with newImage itself.

tips?

thanks

Re: Memory is not getting free'd

Posted: Sun Apr 06, 2014 2:49 pm
by _Yank
This might sound stupid but...
Did you tried using collect garbage function ? Here's how to use it.

Re: Memory is not getting free'd

Posted: Sun Apr 06, 2014 2:54 pm
by bartbes
Adding collectgarbage solves this for me. The reason is that lua doesn't realize your images are this large, and it's not in a hurry to clean up all those tiny values.

Re: Memory is not getting free'd

Posted: Sun Apr 06, 2014 5:20 pm
by T-Bone
Does it perhaps cache and reuse the images? Or in other words, if you alternate between loading two images, does the memory usage still go up or does it stop after they've both been loaded once?