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.