anonymous/lambda event usage causes leak
every time this code runs, memory usage grows. checked via codeLeak
self:addEventListener(Event.KEY_DOWN, function(event) if event.keyCode == KeyCode.UP then self.controls:dispatchEvent(Event.new("shoot")) end end)
local shoot = Event.new("shoot")
self:addEventListener(Event.KEY_DOWN, function(event) if event.keyCode == KeyCode.SPACE then self.controls:dispatchEvent(shoot) end end)
stage:addEventListener(Event.ENTER_FRAME, function() print("MemUsage: ", math.ceil(collectgarbage("count")), "TextureUsage:", application:getTextureMemoryUsage()) end, e)
For the leak version;
Every time this code runs it is generating a new object from Event.new function so it is consuming memory. You can try like this if you are near computer to see if my scenario is correct or not. You can force gideros to collect garbage directly, Maybe it will help.
In this case you are using the local variable shoot for the Event object which is garbage collected by Gideros automatically after it is used.
But as i said those are only my guesses :-?
Are you using sceneManager Class???
'Cos when you change scene it destroy scene, so if some variables or functions aren't inside function class like a local or "self." ... it can cause memory leaks
and yes like you saids Event increase your memory but if you use correctly sceneManager or collectgarbage() I don't believe then you have a lot problems, unless you are using events very intensively but in this case I follow suggestion of @talis
For example when I use my class Box = Core.class(Sprite) it create boxes draggable for Box2D on the main class so:
Likes: totebo, HubertRonald, antix
My game btw has tons going on and runs at a constant 60hz even on a slow device.