audio.dispose()

Type Function
Library audio.*
Return value none
Revision Current Public Release (2014.2381)
Keywords audio, dispose
See also audio.loadSound()
audio.loadStream()

Overview

Releases audio memory associated with the handle.

Gotchas

You must not use the handle once the memory is freed. The audio should not be active (playing or paused) on any channel when you try to free it.

Syntax

audio.dispose( audioHandle )
audioHandle (required)

The handle returned by audio.loadSound() and audio.loadStream() that you want to free.

Example

-- Load a laser sound and a background music stream into memory
local laserSound = audio.loadSound( "laserSound.wav" )
local backgroundMusic = audio.loadStream( "backgroundMusic.m4a" )

-- Play both the sound and the stream
local playLaserSound = audio.play( laserSound )
local playBackgroundMusic = audio.play( backgroundMusic )

-- Stop both the sound and the stream and 'nil' out each reference
audio.stop( playLaserSound )
playLaserSound = nil
audio.stop( playBackgroundMusic )
playBackgroundMusic = nil

-- Dispose the handles from memory and 'nil' out each reference
audio.dispose( laserSound )
audio.dispose( backgroundMusic )
laserSound = nil  --prevents the handle from being used again
backgroundMusic = nil  --prevents the handle from being used again