Hi I am new to Gideros and have a small question regarding classes. My game has a calls called bullet that as you may guess creates bullets with intial velocities. I do not use physics but instead use a runtime listener that updates the bullets location via the self:setPosition() method. This bullet checks if it is off the screen on every frame and if it is I remove it from its parent and nil it using self = nil to be garbage collected and removed from texture memory. The problem is that my texture memory starts at about 1.6mb without the bullet, goes up to 1.7 mb and stays there even after it remove it from its parent. I have checked that it does in fact leave the screen and get nilled. Any suggestions?
Note: within my if statement that check if the bullet is offscreen I have this code:
local parent = self:getParent()
if parent ~= nil then
parent:removeChild(self)
else
self = nil
end
with a print function call I have checked that it tries to nil itself repeatedly since this is in the runtime listener. shouldnt it stop nilling itself after i nil it once and the class destroys itself. Or am I missing some key piece of Lua knoweldge?
Comments
Firstly just a tip, that you could set up an "event listener" to see when object get's garbage collected. like this:
http://www.giderosmobile.com/forum/discussion/comment/12405#Comment_12405
Secondly, is there a reference to the class instance outside the class?
Basically I don't think that nilling self would do much good, because it would probably redefine internal variable value, but if you store class instance somewhere outside, it will not be garbage collected.
Thirdly, for such elements as bullets, it is awesomely efficient to use pools and reuse created objects.
As in:
Likes: seppsepp
http://www.giderosmobile.com/forum/discussion/2818/a-warning-about-memory-management-complacency
Also @ar2rsawseen is right, nilling self in your example will not have any effect and should not be necessary. Have you assigned the object that is referred to by self to another variable that is still kept alive?
Best regards
https://play.google.com/store/apps/developer?id=Into-It+Games
http://appstore.com/LidiaMaximova