Memory Leak

I’m experiencing severe memory leaks when using Lime. I ran through my code several times without finding the source of the problem when I figured it had to be something else causing it. And Lime was the only other code I had included in my program. So to check this, I added the monitorMem() function to the Viewer example from Lime’s member area.
Reference: http://blog.anscamobile.com/2011/08/corona-sdk-memory-leak-prevention-101/

This served as a good test-arena as it used director and therefore had several scenes I could switch between.
When adding the monitorMem code to screen_Main.lua from the Viewer example, I ended up with the following results (test done with Lime 3.4):

Before starting, the memory usage on the screen_Main.lua was:

MemUsage = 391.05
TexMem = 1.13

Then by navigating from the main screen to the selection screen, further to one of the game-scenes, back to the selection screen to finally return to the main screen, I got the following results:

From screen_Main to: (and back)

**1. Hello World:
MemUsage = 738.96 (Leak = 347.91)
TexMem = 2.17 (Leak = 1.04)

  1. Animations:
    MemUsage = 602.18 (Leak = 211.13)
    TexMem = 13.71 (Leak = 12.58)

  2. Physics Slide:
    MemUsage = 593.17 (Leak = 202.12)
    TexMem = 1.65 (Leak = 0.52)

  3. Physics Tower:
    MemUsage = 1004.30 (Leak = 613.25)
    TexMem = 2.17 (Leak = 1.04)

  4. Multiple Tilesets:
    MemUsage = 749.91 (Leak = 358.86)
    TexMem = 3.22 (Leak = 2.09)

  5. Parallax Scrolling:
    MemUsage = 1168.82 (Leak = 777.77)
    TexMem = 4.27 (Leak = 3.14)

  6. Perspective Walls:
    MemUsage = 800.23 (Leak = 409.18)
    TexMem = 4.53 (Leak = 3.40)**
    This is something similar to what I encountered in my own program.

So is there any way to prevent this, or any garbage-removal to take care of from my end, or is this something that needs to be looked into more closely? [import]uid: 129287 topic_id: 24951 reply_id: 324951[/import]

Hello,

Other than making sure you are deleting things correctly the best advice I can give you is to get the memory profiler here:

http://developer.anscamobile.com/forum/2011/11/19/corona®-profiler-line-line-analysis-your-code-promo-codes-included-0

That’s the best $9.99 you will ever spent. Especially mode 4 of the profiler which shows you variables, tables and display objects left behind between scene changes. I too use director and I am not sure how managed Without profiler.

Read the thread above and will understand. Worth 10 times as far I am concern.

Hope this help and good luck.

Mo
[import]uid: 49236 topic_id: 24951 reply_id: 101277[/import]

@lemsim: Thank you for your quick reply and for sharing yor insights on this topic. I have considered buying the profiler, but I decided to wait till a later stage in my development-phase. That was before you kindly shared this information. I didn’t know about the mode 4 as the M.Y.-site doesn’t promote this aspect of the profiler. But now that I know about this feature, I will definitely reconsider buying it soon.

However, the example I ran above didn’t use any of my own code, so there is most likely an issue with Lime that needs to be looked at more closely. [import]uid: 129287 topic_id: 24951 reply_id: 101323[/import]

Sorry for the delay, been really busy as usual.

I will be purchasing the profiler soon myself to look into this issue properly. [import]uid: 119420 topic_id: 24951 reply_id: 101383[/import]

@Dr.Mabuse: No problem. I found a lot of problem with profiler so I am very glad I got it. Time to time I run it just in case (especially in mode 4) It also helped found speed issue since i am working on fast action game.

In term of third party library, that’s a big problem. I usually decide that they are not the issue but I am sure it is a naive. I am sure some library have issue as well but since those library are usually complex and not our code, it is hard to find problem.

I hope your enjoy profiler as I do.

Good luck.

Mo [import]uid: 49236 topic_id: 24951 reply_id: 101438[/import]

I also experienced memory leaks when using Lime.

In my case, lime is using the corona 's “sprite” library to create the image so removeSelf() function won’t release the texture memory.

I try to put dispose() in Lime library and it works fine. [import]uid: 111309 topic_id: 24951 reply_id: 101450[/import]

@lemsim: Just bought and tried Profiler. Seems to be exactly what I needed. This will certainly help me locating the weak spots in my program. Thanks again for your advice.

@ZodiacLeo123: So where exactly did you put dispose() and what “spritesheet” did you use it on? When running profiler’s mode 4, most of what’s causing the leaks seems to be other things than sprites, although I’m not really into how Lime is designed. The major leaks seems to be global variables like lime, Map_mt, Map (even though I’ve nilled this one out!?), lime-utils, TileLayer_mt, TileLayer, Tile_mt, TileSet and TileSet_mt just to mention a few.

[import]uid: 129287 topic_id: 24951 reply_id: 101695[/import]

Lime not only leaks your Texture Memory but also increases your Lua memory if you pass initial variable of Lime to function.

I use lime to create a background from Titleset. Open lime-map.lua, find function Map:destroy(). There are 3 tables from table self: tileLayers,objectLayers,tileSets.

I only add these lines to self.titleSets 's for loop

if (self.tileSets[i].spriteSheet) then
self.tileSets[i].spriteSheet:dispose()
self.tileSets[i].spriteSheet = nil
end

Not sure if you need to dispose other table’s sprite. [import]uid: 111309 topic_id: 24951 reply_id: 101794[/import]

@ZodiacLeo123: Thank you so much for your input. I will take a closer look at it, and hopefully this will solve some of the issues. [import]uid: 129287 topic_id: 24951 reply_id: 101873[/import]