Thursday, February 7, 2013

Potential Memory Leaks


While working on various features (forward and backward accelerometer movement, improved enemy flight patterns, etc), I seem to keep running into confusing and/or misleading error messages. I attribute this in part to the fact that I am not a Corona and/or a Lua expert. However, some of the errors I'm seeing do not seem to make a whole lot of sense. It's hard for me to say as a relative beginner to Corona, but some of the messages may not be completely accurate. At the very least, some of them do not seem to point out the correct line(s) of code causing the problems. 
 
For example, I've been trying to take the code form Level 1 and incorporate it into the other levels. I kept getting an error that was pointing to a null value in the variables bg1 and bg2 (which we are using for the scrolling background images). I tried debugging via display statements, changing various calls, etc., and I was stumped. Eventually, I was able to resolve the problem by changing the name of the methods to be unique to that level. For example, I changed gameloop to gameloopLevel2. Apparently, a conflict was being caused by the use of 2 methods of the same name - even though the methods were in 2 completely different .lua scripts. That may or may not be a function of lua itself. Either way, it would have been easier to debug the problem if the error message generated had somehow pointed that out as a potential cause of the problem. 

One guess I have is that this problem may be related to memory leaks in corona and/or lua. I see quite a few references to memory leak problems in the lua discussions on the www.coronalabs.com site. As I get to be more familiar with the platform, this is one of the problems I hope to get a better understanding of.

No comments:

Post a Comment