I hit an out of memory error and for once I don't know where the leak is...usually I know because the last change I made triggered it, not the case this time (or I just lost track of my shit) - either way, not sure exactly how to debug to trace it down.
Any tips or tricks are appreciated.
I'm sure you've probably tried this already, but in cases like these, I believe printh() and stat(0) are your best friend.
frame = 0 _update = function() -- log the frame to the console printh('frame '..frame) -- profile the current mem usage printh('mem '..flr((stat(0)/1024)*100)..'%) -- [your code here]... -- update frame frame = frame + 1 end
Just play your game and see if any action in particular causes memory usage to spike. If you're not finding any obvious leads, you might have to log out a trace() call on each loop as well.
Once you narrow down what your problematic code may be (special attention to any loops that create tables or functions on the fly), you can confirm by commenting it out and seeing if you still crash. Once you confirm, it's obviously just a matter of refactoring that bit.
Sometimes, it can also be easier to work backwards and comment out all of your code to start. Then, uncomment blocks until you find the memory hog.
Hope that helps!
Thanks for the tips. I'll see if I can make better understanding out of the stat() info. I guess I just don't know what it means outside of "higher is bad" type of thing.
I've been going through my usual process of elimination. I'm sure it's some recursive loop of some sort that I'm missing. Just slow and tedious all the same...grumble grumble...
also make sure all your variables are local when they should be. a big unused table can just stay there if a global references it, preventing the gc from reclaiming it.
I wish we had a collectgarbage(). calling it right before stat(0) would help a lot.
[Please log in to post a comment]