pgimeno wrote: ↑Wed Aug 19, 2020 11:08 pm
gcmartijn wrote: ↑Wed Aug 19, 2020 7:22 pm
Do we always need to set variable to nil for the garbage collector ?
No. Going out of scope is equivalent to setting it to nil.
Sometimes, Löve objects take a long time to be cleaned up by the GC, letting many of them to accumulate and take a lot of memory. In these cases, it's best to explicitly release them with
Object:release. I wonder if that's what's happening here.
Jeeper wrote: ↑Wed Aug 19, 2020 9:55 pm
Did you miss type or does the 32bit version have support for more memory? That would make no sense?
The 1 GB limit in 64 bits applies to Linux.
https://stackoverflow.com/questions/351 ... -platforms
http://timetobleed.com/digging-out-the- ... egression/
@pgimeno
I was searching for memory fluctuations inside my code.
And I never set temp tables to nil (and other variables), after you did mention that leaving a function is automaticity (at some point) free up some memory. This make the code more readable (less lines).
But now I did test something, and want to know if this behaviour is oke.
Situation 1: a function create a huge temp table, and the garbage count is now 1024 big.
I did thought that is was not, after your comment.
But is this garbage a problem? at this point ? Or will new object inside the garbage replaces (overwritten), and is in my case 1024 the max garbage I can have.
Code: Select all
function bla()
t = {}
for i = 1, 100000000 do
table.insert(t, "hello")
end
end
function love.load()
bla() -- garbage count == 1024 now
end
function love.draw()
love.graphics.print(
string.format(
"Memory: gfx=%.1fMiB lua=%.1fMiB",
love.graphics.getStats().texturememory / 1024 ^ 2,
collectgarbage "count" / 1024
),10,25)
end
Situation 2: the same, but now I want to manual remove it, it don't work.
Code: Select all
function bla()
t = {}
for i = 1, 100000000 do
table.insert(t, "hello")
end
end
function love.load()
bla() -- garbage count == 1024 now
collectgarbage("collect") -- does nothing
end
Situation 3: works
Code: Select all
function bla()
t = {}
for i = 1, 100000000 do
table.insert(t, "hello")
end
t = nil -- we don't need it as garbage
end
function love.load()
bla() -- garbage count == 0.x now
end
I like situation 3 when searching for memory issues or fluctuations in the future.
But will give it other benefits? I have to add multiple lines to my code.
And I don't know why situation 2 did not work, but I don't really use that.
I was thinking about manual garbage collections (turn it off), and only 'collect'/remove the garbage on a frame update (to see what happens).