Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-03-2010, 10:14 AM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 16
ufbobbo is on a distinguished road
Default AVAudioPlayer not unloading cached memory after each new allocation

I am seeing in Instruments that when I play a sound via the standard "AddMusic" example method that Apple provides, it allocates 32kb of memory via the prepareToPlay call (which references the AudioToolBox framework's Cache_DataSource::ReadBytes function) each time a new player is allocated (i.e. each time a different sound is played). However, that cached data never gets released.

This obviously poses a huge problem if it doesn't get released and you have a lot of sound files to play, since it tends to keep allocating memory and eventually crashes if you have enough unique sound files (which I unfortunately do).

Have any of you run across this or what am I doing wrong in my code? I've had this issue for a while now and it's really bugging me since my code is verbatim of what Apple's is (I think).

How I call the function:

Code:
    - (void)playOnce:(NSString *)aSound {
	
	// Gets the file system path to the sound to play.
	NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:aSound ofType:@"caf"];  
	
	// Converts the sound's file path to an NSURL object
	NSURL *soundURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
	self.soundFileURL = soundURL;
	[soundURL release];
	
	AVAudioPlayer * newAudio=[[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error:nil];  
	self.theAudio = newAudio; // automatically retain audio and dealloc old file if new m4a file is loaded
	
	[newAudio release]; // release the audio safely
	
	// this is where the prior cached data never gets released
	[theAudio prepareToPlay];

    // set it up and play
	[theAudio setNumberOfLoops:0];
	[theAudio setVolume: volumeLevel];
	[theAudio setDelegate: self];
	[theAudio play];

    }
and then theAudio gets released in the dealloc method of course.
ufbobbo is offline   Reply With Quote
Old 05-03-2010, 06:07 PM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 16
ufbobbo is on a distinguished road
Default

Please guys, if there's any advice you can lend to me it would be greatly appreciated.
ufbobbo is offline   Reply With Quote
Reply

Bookmarks

Tags
audiotoolbox, avaudioplayer, malloc, preparetoplay

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 335
20 members and 315 guests
Abidullah, baja_yu, cgokey, Domele, Duncan C, Fstuff, gbenna, givensur, guusleijsten, HowEver, jbro, mdpauley, n00b, newDev, Sami Gh, seokwon lee, SLIC, stanny, Steven.C, WheyLabs
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,877
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:39 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0