I've got a monster memory leak in my game.
Upon finishing the level, and restarting the same level, the memory usage increases by around 800.
I'm using scene manager, stopping all timers, keeping everything in the scene scope.
There's something glaring that I've missed - are there any obvious gotchas I can look into? Or any way to 'see' what's causing the memory hog?
Thanks
Comments
Check if you don't create any global objects (maybe forgot to type local before variable name), especially when storing textures, sounds or fonts.
But for now, don't know a better way of debugging this as commenting out the parts of the code and see if that changes
Likes: ar2rsawseen, talis
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
Likes: ar2rsawseen
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
So you can print grpObject:getNumOfChildren when restart level to see the difference (to check if your obj is doubled or not)
Ultimate Games on Appstore
Ultimate Games on Google Play
Because of the way the GC works, you won't get an accurate reading until it's been run a couple of times, so you'll often see things like
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
I thought I'd put together a little bit of instrumentation code that allows you to dump a count of all the objects in existence at any time, listed by class name. That way you can compare the snapshot at different points in your app to see what types of object are leaking.
The code relies on a modified version of the classes.lua that Gideros uses internally (this was published by @atilim in another thread a couple of weeks back). It also relies on the proxy hack by @john26 above.
Unfortunately, due to a limitation in the way the built-in classes are currently handled, the code doesn't list instances of these classes, only your user-defined ones. I've posted a question asking if this can be changed, but I thought the existing version might be useful anyway, so I'm attaching it here.
BTW, don't leave the "leaky.lua" in your project when you're not debugging a memory leak as the extra work it does will be detrimental to overall performance.
best regards
Likes: omer, techdojo, john26, vitalitymobile, chipster123, pie, totebo
Going to tackle the monster leak from hell now.
Dislikes: Yan
Thanks. What are the steps to getting this running in a project.
I tried:
1) Adding:
classes.lua
leaky.lua to
bag.lua
2) require "classes"
3) require "leaky"
4) use code:
collectgarbage("collect")
EventDispatcher.printAllInstances("message here")
The error was:
Try this:
1) Add classes.lua, leaky.lua, bag.lua to your project
2) Right click on classes.lua and choose "Exclude from Execution"
3) Add a file called "init.lua" to your project with the single line, require "classes".
4) Add the lines:
collectgarbage("collect")
EventDispatcher.printAllInstances("message here")
somewhere in your project where you want to check the memory.
When you run the project, you should see the message "MODIFIED classes.lua INITIALISED" appear before anything else.
If this doesn't work, I'd need to see what line is actually causing the error in your code. In the example you show it is at line 42 in "main.lua".
best regards
Edit: Fixed the memory leak.
1) Needed to call vPad:stop()
(I'm using TNT Virtual Pad)
2) Needed to call Timer:stopAll()
Now, if we can just get those modifications to the class system then tracking memory should be even easier.
Best regards
Hi, I was pointed to this topic because i'm having some issues with performance on my game.
I tried to use your solution to examine memory leaks, but even after following the steps, I'm having this error:
1) Add classes.lua, leaky.lua, bag.lua to your project
2) Right click on classes.lua and choose "Exclude from Execution"
3) Add a file called "init.lua" to your project with the single line, require "classes".
4) Add the lines:
collectgarbage("collect")
EventDispatcher.printAllInstances("message here")
And when I put lines:
*** OBJECT SNAPSHOT 12/24/13 09:38:38 ***
*** OBJECT SNAPSHOT END ****
but nevertheless I have errors which I've shown above.
I tested my app in Gideros 2013.06.1 and 2013.09.1.
@Bowerandy, could you please help to find the solution for this issue?
@romka, have you figured this out? It looks like your project isn't using @bowerandy 'classes.lua' file because your output above is not showing the message
When all you get is
it happens when classes.lua is required in your project and it's loaded, (that's why you can read "MODIFIED classes.lua INITIALISED") but it's too late...
I had init.lua in a subdirectory (on my harddrive, inside my app root directory). It should be placed in the root directory of your project on your harddisk (and in your project) otherwise it won't be loaded first (check it with Code dependencies > Call Order).
p.s - thank you @bowerandy for sharing this it's really useful!
(That why we have error: bag.lua:9: table index is nil -> this because of: EventDispatcher._allObjectsBag:add(self.class) - > here self.class is nil )
I have a quick fix version here, and then it print out as normal:
Likes: chipster123, pie
Likes: vitalitymobile