Memory leak [BUG]

Hi,

I’m using in my project the method: newSpriteSheetFromData

When I load/unload the sprites with this method I get a memory leak of 2-3Mb.

I have submitted a bug report: Case 10358

I want to know if anyone else using this method to load sprite sheets gets this memory leak?

Thank you

[import]uid: 89239 topic_id: 18766 reply_id: 318766[/import]

Are you disposing of the sheet? I use it in Spriteloq without issue. [import]uid: 27183 topic_id: 18766 reply_id: 72247[/import]

yes, I use dispose…

Anyone else having this problem??? [import]uid: 89239 topic_id: 18766 reply_id: 72428[/import]

Post the offending code. I’ve been using newSpriteSheetFromData from build 336 all the way to 689 without leaks. [import]uid: 27183 topic_id: 18766 reply_id: 72439[/import]

http://www.fanstudio.co.uk/bug.zip

watch the console when running on your device… [import]uid: 89239 topic_id: 18766 reply_id: 72442[/import]

Ok just checked out the code, I don’t see the 2-3MB leak you’re talking about.

BEFORE LOAD .....................................................................
MemUsage: 80.939453125
TexMem: 0
AFTER LOAD .....................................................................
MemUsage: 84.037109375
TexMem: 2.097152
AFTER REMOVE .....................................................................
MemUsage: 82.96875
TexMem: 2.097152
Delay call......................................................
MemUsage: 82.8974609375
TexMem: 0

Updated the numbers. [import]uid: 27183 topic_id: 18766 reply_id: 72443[/import]

AFTER REMOVE …
MemUsage: 82.96875
TexMem: 2.097152

Why after remove it’s still keeping the TexMem: 2.097152 ???

After remove you should have the initial memory:

BEFORE LOAD …
MemUsage: 80.939453125
TexMem: 0

[import]uid: 89239 topic_id: 18766 reply_id: 72451[/import]

yeah, but it dropped to 0 in the last entry. I didn’t look at you code to see what’s causing the delay, but the texture memory is removed

AFTER REMOVE …
MemUsage: 82.96875
TexMem: 2.097152
Delay call…
MemUsage: 82.8974609375
TexMem: 0

BEFORE LOAD …
MemUsage: 80.939453125
Delay call…
MemUsage: 82.8974609375
TexMem: 0

82 Mb instead of 80Mb… there is a difference. [import]uid: 89239 topic_id: 18766 reply_id: 72463[/import]

http://www.lua.org/manual/5.1/manual.html

collectgarbage (opt [, arg])

This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt:

“stop”: stops the garbage collector.
“restart”: restarts the garbage collector.
“collect”: performs a full garbage-collection cycle.
"count": returns the total memory in use by Lua (in Kbytes). [import]uid: 27183 topic_id: 18766 reply_id: 72466[/import]

That should be Kb not Mb. [import]uid: 27183 topic_id: 18766 reply_id: 72464[/import]

@don ,

I have to thank you for posting this info. I was thinking that the count of the GC was in Mega Bytes instead Kb, it`s good. :slight_smile:
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 18766 reply_id: 72567[/import]

To see it in MB do this;

[lua]local function monitorMem(event)
collectgarbage(“collect”)

print( “\nMemUsage: " … (collectgarbage(“count”)/1000) … " MB”)
print("Texture Usage " … system.getInfo( “textureMemoryUsed” ) / 1000000)

return true
end

Runtime:addEventListener(“enterFrame”, monitorMem)[/lua]

Obviously not Runtime if you don’t want it chaining.

Peach :slight_smile: [import]uid: 52491 topic_id: 18766 reply_id: 72615[/import]

@Don, thank you for the tip!

I’m relieved to hear that :slight_smile: [import]uid: 89239 topic_id: 18766 reply_id: 72669[/import]

Hey FS , do you mind telling how are you checking your used memory?

Thanks in advance.

Rodrigo. [import]uid: 89165 topic_id: 18766 reply_id: 72719[/import]

Hi Rodrigo,

You can use the function mentioned by Peach Pellen, it works great!

[import]uid: 89239 topic_id: 18766 reply_id: 72722[/import]

@office83, @Rodrigo,

Yeah it’d be ridiculous if an app that did nothing took up 80 MB of memory.

@peach,

Does it makes more sense to divide by 1024 and 1024^2 for more accurate numbers for the memory since we’re talking RAM and not “disk” space? http://en.wikipedia.org/wiki/Megabyte [import]uid: 27183 topic_id: 18766 reply_id: 72728[/import]

@FS and @don - Thank you for the tips!

PS: The results of Peach`s function is so showed in MB already.

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 18766 reply_id: 72792[/import]

Hey Don,

That’s a good point. The code is not something I can take credit for, I just share it :wink:

May be worth switching to 1024 as suggested :slight_smile:

Peach [import]uid: 52491 topic_id: 18766 reply_id: 72853[/import]