Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By : Michelle M Fernandez
Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By: Michelle M Fernandez

Overview of this book

Table of Contents (19 chapters)
Corona SDK Mobile Game Development Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Memory management


It is important to call audio.dispose() on your loaded audio when you are completely done with the audio file. Doing so allows you to recover the memory.

audio.dispose()

The audio.dispose() function releases the audio memory associated with the handle.

The syntax is audio.dispose( audioHandle ).

The parameter is as follows:

  • audioHandle: The handle returned by the audio.loadSound() or audio.loadStream() functions that you want to free.

    Tip

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

For example:

mySound = audio.loadSound( "sound1.wav" )
myMusic = audio.loadStream( "music.mp3" )

audio.dispose( mySound )
audio.dispose( myMusic )

mySound = nil
myMusic = nil

Have a go hero – disposing audio

You have just learned how to dispose audio files properly to recover memory in your application. Try the following:

  • Load your audio file and have it play for a specified time. Create a function that will dispose...