Page 1 of 2

[0.10.2] love.math.compress/decompress seems to be leaking memory

Posted: Thu Mar 01, 2018 11:41 am
by Whatthefuck
Hello, like the title says, seems like calls to love.math.compress/decompress leak about ~200kb of memory (or maybe even more), independent of the compression algorithm. (I've tried lz4 and zlib so far, with different compression levels)

I'm writing savefiles to disk, and if I compress the written data with love.math.compress, then I get memory leaks. If I don't - no memory leak occurs. Additionally, this leak occurs even without writing the compressed output to a file. just having a for i = 1, 100 do love.math.compress(data, "compressionFormat", compressionLevel) end will leak 50 megabytes of memory at the end of the iteration cycle.

Edit 1: amount of leaked memory seems to depend on size of the string for compression passed into the love.math.compress/decompress call.

Re: [0.10.2] love.math.compress/decompress seems to be leaking memory

Posted: Thu Mar 01, 2018 11:47 am
by grump
How did you detect the leak? Keep in mind, Lua memory is garbage collected, i. e. not immediately freed after use, but only after the next collection cycle. Calling collectgarbage() forces the garbage to be collected immediately, causes unused memory to be freed and usually makes such "leaks" disappear.

Re: [0.10.2] love.math.compress/decompress seems to be leaking memory

Posted: Thu Mar 01, 2018 11:57 am
by Whatthefuck
I called collectgarbage() twice to run a full GC cycle after compressing the data, it doesn't free it up, and the memory usage by love2d keeps on increasing after each compression call. I'm very sure this is a memory leak, because like I said, this does not occur if I just write the serialized data straight to disk without compressing it.

Re: [0.10.2] love.math.compress/decompress seems to be leaking memory

Posted: Thu Mar 01, 2018 12:16 pm
by Whatthefuck
Here's the baseline memory usage:
Image
And after hammering ~2k compression calls:
Image

Calling collectgarbage any amount of times has no effect on the memory.

Re: [0.10.2] love.math.compress/decompress seems to be leaking memory

Posted: Thu Mar 01, 2018 2:21 pm
by zorg
Before anything, could you test this with the newest 0.11? Maybe it was a known issue and has been fixed already; note that de/compression went from the love.math to the love.data namespace.

Re: [0.10.2] love.math.compress/decompress seems to be leaking memory

Posted: Thu Mar 01, 2018 2:28 pm
by grump
Can confirm that love.math.compress in 0.10.2 (Debian 9 x64) seems to eat up memory:

Code: Select all

local rand = {}
for i = 1, 2^16 do
	rand[i] = string.char(love.math.random(32, 127))
end
local str = table.concat(rand)

for i = 1, 2^14 do
	love.math.compress(str)
end
collectgarbage()
Process memory consumption goes up to ~1GB, never goes down. Can't test any other version right now.

Re: [0.10.2] love.math.compress/decompress seems to be leaking memory

Posted: Thu Mar 01, 2018 2:31 pm
by Whatthefuck
zorg wrote: Thu Mar 01, 2018 2:21 pm Before anything, could you test this with the newest 0.11? Maybe it was a known issue and has been fixed already; note that de/compression went from the love.math to the love.data namespace.
Any windows builds of it anywhere for a quick test?

Re: [0.10.2] love.math.compress/decompress seems to be leaking memory

Posted: Thu Mar 01, 2018 2:36 pm
by zorg
Whatthefuck wrote: Thu Mar 01, 2018 2:31 pm
zorg wrote: Thu Mar 01, 2018 2:21 pm Before anything, could you test this with the newest 0.11? Maybe it was a known issue and has been fixed already; note that de/compression went from the love.math to the love.data namespace.
Any windows builds of it anywhere for a quick test?
https://love2d.org/builds/

slime's appveyor, pay attention to choose the latest though, i managed to get the wrong one once. :p

Re: [0.10.2] love.math.compress/decompress seems to be leaking memory

Posted: Thu Mar 01, 2018 11:12 pm
by slime
There is a memory leak in love.math.compress in 0.10.2, it's already been fixed in the upcoming 0.11.

Re: [0.10.2] love.math.compress/decompress seems to be leaking memory

Posted: Fri Mar 02, 2018 10:42 am
by Whatthefuck
Awesome! Thanks for clarifying.