Removing audio question

When assigning different audio handles to the same variable, as shown below, does the previous audio reference need to be disposed of before the variable gets a new assignment? Or does reassigning the variable clear the reference?

--Would this commented-out code be necessary to avoid a memory leak? --this loops every half-second or so --if mainGroup.footChannel ~= nil then --audio.stop(mainGroup.footChannel) --audio.dispose(mainGroup.footChannel); mainGroup.footChannel=nil --end local n = math.random(1,4) mainGroup.footChannel = audio.play(footSoundTable[n])

Thanks.

To avoid memory leaks it is a good idea to do so.

It looks like your code is good to go.

Are you having an issue ?

Larry

I was seeing some crashes and wasn’t sure whether it was due to memory issues. I’m mainly curious about whether overwriting an audio handle is as effective as disposing of it and nilling it before reuse. I’d rather not nil unnecessarily.

You disposed it so you should not have to - nil - it but that should not hurt anything.

Larry

To avoid memory leaks it is a good idea to do so.

It looks like your code is good to go.

Are you having an issue ?

Larry

I was seeing some crashes and wasn’t sure whether it was due to memory issues. I’m mainly curious about whether overwriting an audio handle is as effective as disposing of it and nilling it before reuse. I’d rather not nil unnecessarily.

You disposed it so you should not have to - nil - it but that should not hurt anything.

Larry