It looks like you're new here. If you want to get involved, click one of these buttons!
print("TextureMemory at startup", application:getTextureMemoryUsage()) local buttonPlay = Button.new(Bitmap.new(Texture.new("btnNormal.png", true)), Bitmap.new(Texture.new("btnPressed.png", true))) buttonPlay:setPosition(100, 100) print("TextureMemory after loading buttonPlay", application:getTextureMemoryUsage()) local function playClicked() print("play clicked") playTween = GTween.new(buttonPlay, 1, {alpha=0}, {delay=0, easing=easing.linear, dispatchEvents=true}) playTween:addEventListener("complete", function() playTween = nil unloadButton() print("TextureMemory after unloading button on Tween complete", application:getTextureMemoryUsage()) end) end buttonPlay:addEventListener("click", playClicked) stage:addChild(buttonPlay) function onMouseDown() unloadButton() print("TextureMemory after unloading button onMouseDown", application:getTextureMemoryUsage()) end stage:addEventListener(Event.MOUSE_DOWN, onMouseDown) function unloadButton(msg) buttonPlay:removeEventListener("click", playClicked) stage:removeChild(buttonPlay) buttonPlay = nil collectgarbage("collect") collectgarbage("collect") collectgarbage("collect") end |
Comments
But all in all it seems you are doing all right.
What you can do, is to attach this kind of witchery to your Button (or any other class/object) class:
Likes: SinisterSoft
But, any clues as to why there would be a difference between Scenario 1 and scenario 2 above? Without tween, the memory comes down from 128 to 64 after unloading the button. But with tween, there is no reduction. Seems like setting the tween object to nil is not enough and it is somehow holding on to the target button?