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 06-02-2010, 03:01 PM   #1 (permalink)
See Scream Queens on VH1
 
Join Date: Jun 2010
Location: Los Angeles
Posts: 2
Biagio is on a distinguished road
Default AVAudio Memory Leak: Stack trace and code included...

First, thanks for having a look. My first post here, so apologies if I'm putting up too much.

Part of this app is a "Scream" button that plays random screams from cast members of a TV show. I have to bang on the app quite a while to see a memory leak in Instruments, but it's there, occasionally coming up (every 45 seconds to 2 minutes.) The leak is 3.50kb when it occurs. Haven't been able to crack it for several hours. Any help appreciated.

Instruments says this is the offending code line:

Code:
[appSoundPlayer play];
that's linked to from line 9 of the below stack trace:

Quote:
0 libSystem.B.dylib malloc

1 libSystem.B.dylib pthread_create

2 AudioToolbox CAPThread::Start()

3 AudioToolbox GenericRunLoopThread::Start()

4 AudioToolbox AudioQueueNew(bool, AudioStreamBasicDescription const*, TCACallback const&, CACallbackTarget const&, unsigned long, OpaqueAudioQueue*)

5 AudioToolbox AudioQueueNewOutput

6 AVFoundation allocAudioQueue(AVAudioPlayer, AudioPlayerImpl*)

7 AVFoundation prepareToPlayQueue(AVAudioPlayer*, AudioPlayerImpl*)

8 AVFoundation -[AVAudioPlayer prepareToPlay]

9 Scream Queens -[ScreamViewController scream:] /Users/laptop2/Desktop/ScreamQueens Versions/ScreamQueens25/Scream Queens/Classes/../ScreamViewController.m:210

10 CoreFoundation -[NSObject performSelector:withObject:withObject:]

11 UIKit -[UIApplication sendAction:to:from:forEvent:]

12 UIKit -[UIApplication sendAction:toTarget:fromSender:forEvent:]

13 UIKit -[UIControl sendAction:to:forEvent:]

14 UIKit -[UIControl(Internal) _sendActionsForEvents:withEvent:]

15 UIKit -[UIControl touchesEnded:withEvent:]

16 UIKit -[UIWindow _sendTouchesForEvent:]

17 UIKit -[UIWindow sendEvent:]

18 UIKit -[UIApplication sendEvent:]

19 UIKit _UIApplicationHandleEvent

20 GraphicsServices PurpleEventCallback

21 CoreFoundation CFRunLoopRunSpecific

22 CoreFoundation CFRunLoopRunInMode

23 GraphicsServices GSEventRunModal

24 UIKit -[UIApplication _run]

25 UIKit UIApplicationMain

26 Scream Queens main /Users/laptop2/Desktop/ScreamQueens Versions/ScreamQueens25/Scream Queens/main.m:14

27 Scream Queens start
Here's from .m, next line begins the block with the offending code, line commented below

- (IBAction) scream: (id) sender
{
//Play a click sound effect
SystemSoundID soundID;
NSString *sfxPath = [[NSBundle mainBundle]
* * * * * * * * * * * * *pathForResource:@"aClick" ofType:@"caf"]; * *

* * AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:sfxPath],&soundID);
* * AudioServicesPlaySystemSound (soundID);


* * // Because someone may slam the scream button over and over,
* * //must stop current sound, then begin next *
* * if ([self appSoundPlayer] != nil)
* * {
* * * * [[self appSoundPlayer] setDelegate:nil];
* * * * [[self appSoundPlayer] stop];
* * * * [self setAppSoundPlayer: nil];

* * }


* * //after selecting a random index in the array (did that in View Did Load),
* * //we move to the next scream on each click.

* * //First check...
* * //Are we past the end of the array?

* * if (currentScreamIndex == [screams count])
* * {
* * * * currentScreamIndex = 0;
* * }


* * //Get the string at the index in the personScreaming array

* * currentScream = [screams objectAtIndex: currentScreamIndex];


* * //Get the string at the index in the personScreaming array
* * NSString *screamer = [personScreaming objectAtIndex:currentScreamIndex];

* * //Log the string to the console
* * NSLog (@"playing scream: %@", screamer);

* * // Display the string in the personScreamingField field
* * NSString *listScreamer = [NSString stringWithFormat:@"scream by: %@", screamer];

* * [personScreamingField setText:listScreamer];


* * // Gets the file system path to the scream to play.
* * NSString *soundFilePath = [[NSBundle mainBundle] * *pathForResource: * *currentScream
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ofType: * * * * * * * @"caf"];

* * // Converts the sound's file path to an NSURL object
* * NSURL *newURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
* * self.soundFileURL = newURL;
* * [newURL release];
* * [[AVAudioSession sharedInstance] setDelegate: self];
* * [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];

* * // Registers the audio route change listener callback function
* * AudioSessionAddPropertyListener (
* * * * * * * * * * * * * * * * * * *kAudioSessionProperty_AudioRouteChange,
* * * * * * * * * * * * * * * * * * *audioRouteChangeListenerCallback,
* * * * * * * * * * * * * * * * * * *self
* * * * * * * * * * * * * * * * * * *);

* * // Activates the audio session.

* * NSError *activationError = nil;
* * [[AVAudioSession sharedInstance] setActive: YES error: &activationError];

* * // Instantiates the AVAudioPlayer object, initializing it with the sound
* * AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error: nil];

* * //Error check and continue
* * if (newPlayer != nil)
* * {
* * * * self.appSoundPlayer = newPlayer;
* * * * [newPlayer release];
* * * * [appSoundPlayer prepareToPlay];
* * * * [appSoundPlayer setVolume: 1.0];
* * * * [appSoundPlayer setDelegate:self];
* * * * //NEXT LINE IS FLAGGED BY INSTRUMENTS AS LEAKY
* * * * [appSoundPlayer play];
* * * * playing = YES;

* * * * currentScreamIndex++;
[/code]

Here's my dealloc:

Code:
- (void)dealloc {
* * [appSoundPlayer stop];
* * [appSoundPlayer release], appSoundPlayer = nil;
* * [soundFileURL * * * * * * * release];
* * [super dealloc];
}


@end
Thanks so much for reading this far! Any input appreciated. Sorry for long first post, but was hoping it would make it easier to figure out where I went wrong.
Biagio is offline   Reply With Quote
Old 06-02-2010, 03:45 PM   #2 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

Is this when running on the simulator or the phone? This looks like a leak I get in the simulator, that goes away when I build for the device.
JasonR is offline   Reply With Quote
Old 06-02-2010, 06:23 PM   #3 (permalink)
See Scream Queens on VH1
 
Join Date: Jun 2010
Location: Los Angeles
Posts: 2
Biagio is on a distinguished road
Default

Quote:
Originally Posted by JasonR View Post
Is this when running on the simulator or the phone? This looks like a leak I get in the simulator, that goes away when I build for the device.
I'm getting this on the iPhone itself. Again, I really have to bang away on it, slamming the scream button over and over again...it seems to occur during a "hang" (something that only happens when running on instruments.) I'm so tempted to say, "Ah, it's just instruments" but I know better. Still, I can't figure it out.
Biagio is offline   Reply With Quote
Reply

Bookmarks

Tags
avaudioplayer, memory leaks

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: 354
13 members and 341 guests
ajay123123, Anwerbl, Arty Tales, ashaman64, baja_yu, ChrisYates, HemiMG, mini998, mottdog, newDev, Objective Zero, oceanlablight, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,878
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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