If I often call a sound like the following in different scene (without variable to unload), does it takes always more and more memory?
audio.play(audio.loadSound(“sound.wav”))
If I often call a sound like the following in different scene (without variable to unload), does it takes always more and more memory?
audio.play(audio.loadSound(“sound.wav”))
Well, I made some tests and the memory didn’t increase, that’s cool
You should not load sounds that way because you never have a handle to dispose of them later. If you’re going to be using a sound over and over, your best bet is to load it in main.lua and save a reference to it in a data structure that you can get to from any module. See: http://www.coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/ to learn how to have global like data that’s not global.
Then just use audio.play(soundHandle) when you want to play it.
Even though your tests are not showing memory issues, you are continually loading the sound which takes time and resources which slows down the overall playing of the sound. Audio does take up memory and needs disposed when you’re done with it. There are however sounds that you use over and over and those you can keep around, but you really only want one copy of it.
Rob
I simply didn’t notice memory problem but you right for a “click” sound it’s better to load it just one time. I was into this because I was wondering why memory continiously increase in my project… and I found why!
There’s a “bug” with transition.blink or transition.to (with iterations=0). They don’t stop to increase the memory even if you cancel and nil the reference!!
Can you provide an example that shows this memory leak? I’ve got another thread where they can’t pin it down. We want engineering to look at this, but without a test case showing it (as it’s passing our tests) they won’t be able to find it.
Rob
Can you make it a zip file? I don’t have any apps to deal with .rar files.
Thanks
Rob
I’m on a Mac. But I made a couple of changes:
function scene:createScene(evt) local group = self.view print("create1") rect=display.newRect(group,300,400,400,400) rect2 = display.newRect(group,300,400,300,300) end -------------------------------------------- function scene:willEnterScene(evt) local group = self.view print("willEnter1") end -------------------------------------------- function scene:enterScene(evt) local group = self.view print("enter1") if storyboard.getPrevious()~=nil then storyboard.removeScene(storyboard.getPrevious()) end rect:addEventListener("touch",function() storyboard.gotoScene("scn2","fade",1000) end) t = transition.to(rect,{time=100,alpha=0.5,iterations=0}) end -------------------------------------------- function scene:exitScene(evt) local group = self.view transition.cancel(t) t = nil print("exit1") end
And when I click back to scene 1, I get the same memory footprint that I do from earlier versions. There will be some increase because of new tables being created and such, but this isn’t a leak. Memory doesn’t keep going up once I cancel the transition and nil it.
EDIT: I also added:
local rect2
local t
at the top
Rob
I’m on windows and now it works (I don’t understand why not yesterday!) when the transition is cancelled and niled ONLY.
Thanks for your help :)
Well, I made some tests and the memory didn’t increase, that’s cool
You should not load sounds that way because you never have a handle to dispose of them later. If you’re going to be using a sound over and over, your best bet is to load it in main.lua and save a reference to it in a data structure that you can get to from any module. See: http://www.coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/ to learn how to have global like data that’s not global.
Then just use audio.play(soundHandle) when you want to play it.
Even though your tests are not showing memory issues, you are continually loading the sound which takes time and resources which slows down the overall playing of the sound. Audio does take up memory and needs disposed when you’re done with it. There are however sounds that you use over and over and those you can keep around, but you really only want one copy of it.
Rob
I simply didn’t notice memory problem but you right for a “click” sound it’s better to load it just one time. I was into this because I was wondering why memory continiously increase in my project… and I found why!
There’s a “bug” with transition.blink or transition.to (with iterations=0). They don’t stop to increase the memory even if you cancel and nil the reference!!
Can you provide an example that shows this memory leak? I’ve got another thread where they can’t pin it down. We want engineering to look at this, but without a test case showing it (as it’s passing our tests) they won’t be able to find it.
Rob
Can you make it a zip file? I don’t have any apps to deal with .rar files.
Thanks
Rob
I’m on a Mac. But I made a couple of changes:
function scene:createScene(evt) local group = self.view print("create1") rect=display.newRect(group,300,400,400,400) rect2 = display.newRect(group,300,400,300,300) end -------------------------------------------- function scene:willEnterScene(evt) local group = self.view print("willEnter1") end -------------------------------------------- function scene:enterScene(evt) local group = self.view print("enter1") if storyboard.getPrevious()~=nil then storyboard.removeScene(storyboard.getPrevious()) end rect:addEventListener("touch",function() storyboard.gotoScene("scn2","fade",1000) end) t = transition.to(rect,{time=100,alpha=0.5,iterations=0}) end -------------------------------------------- function scene:exitScene(evt) local group = self.view transition.cancel(t) t = nil print("exit1") end
And when I click back to scene 1, I get the same memory footprint that I do from earlier versions. There will be some increase because of new tables being created and such, but this isn’t a leak. Memory doesn’t keep going up once I cancel the transition and nil it.
EDIT: I also added:
local rect2
local t
at the top
Rob
I’m on windows and now it works (I don’t understand why not yesterday!) when the transition is cancelled and niled ONLY.
Thanks for your help :)