I recently discovered that I have some major memory problems in my game. After reading my android console log, I reached a message that said “out of memory” and this seemed to be the reason for the app randomly shutting down, stopping, not loading correctly etc at a certain point during the storyboard scenes.
After researching about “localizing” lua functions, I have a few questions.
Right now my main lua file has a lot of functions and variables. Which are all global [duh] I realize that I have some changes to make because some of these functions are only used once, and in such case, should be in whichever scene they are used in and local.
Now, if a global variable exists, then there is an “imaginary box” for data to be stored in. Unless you nil it out, and remove, that box remains in the memory’s inventory forever. Correct??
Compared to a local variable, which only requires nil-ing, to be removed for memory. Please correct me if I am wrong.
My first question is: how do global FUNCTIONS effect memory? are they stored anywhere in the first place, because when I make a global function, i simply,make it there is no setting it into a variable…
My second question is: lets say i have a considerable sized table that has vars that need to be remembered throughout the game. [imagine a person, his deck of cards, their pictures, his name, and etc.] should I put this in a module lua file?? and then make it local in that? What is the difference between requiring a module with a local table, v. creating a global table in the main? How do you do this?
My third question: I used print("mem "…collectgarbage(“count”)) in order to keep track of memory usage, but I see the number constantly increasing and decreasing…what does this number mean? Is there a max memory usage limit where an app starts to become slow etc.?
Thanks!