Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 867295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:57:07+00:00 2026-05-15T09:57:07+00:00

Part of this app is a Scream button that plays random screams from cast

  • 0

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:

[appSoundPlayer play]; 

that’s linked to from line 9 of the below stack trace:

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 .h:

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
#import <AudioToolbox/AudioToolbox.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>

@interface ScreamViewController : UIViewController <UIApplicationDelegate,        AVAudioPlayerDelegate, MFMailComposeViewControllerDelegate> {





//AudioPlayer related
AVAudioPlayer           *appSoundPlayer;
NSURL                   *soundFileURL;
BOOL                    interruptedOnPlayback;
BOOL                    playing;

//Scream button related
IBOutlet UIButton       *screamButton;
int                     currentScreamIndex;
NSString                *currentScream;
NSMutableArray          *screams;
NSMutableArray          *personScreaming;
NSMutableArray          *photoArray;
int                     currentSayingsIndex;
NSString                *currentButtonSaying;
NSMutableArray          *funnyButtonSayings;
IBOutlet UILabel        *funnyButtonSayingsLabel;
IBOutlet UILabel        *personScreamingField;
IBOutlet UIImageView    *personScreamingImage;



//Mailing the scream related
    IBOutlet UILabel        *mailStatusMessage;
    IBOutlet UIButton       *shareButton;


}
//AudioPlayer related
@property (nonatomic, retain)   AVAudioPlayer                   *appSoundPlayer;
@property (nonatomic, retain)   NSURL                           *soundFileURL;
@property (readwrite)           BOOL                            interruptedOnPlayback;
@property (readwrite)           BOOL                            playing;

//Scream button related
@property (nonatomic, retain)   UIButton                        *screamButton;
@property (nonatomic, retain)   NSMutableArray                  *screams;
@property (nonatomic, retain)   NSMutableArray                  *personScreaming;
@property (nonatomic, retain)   NSMutableArray                  *photoArray;
@property (nonatomic, retain)   UILabel                         *personScreamingField;
@property (nonatomic, retain)   UIImageView                     *personScreamingImage;
@property (nonatomic, retain)   NSMutableArray                  *funnyButtonSayings;
@property (nonatomic, retain)   UILabel                         *funnyButtonSayingsLabel;


//Mailing the scream related
@property (nonatomic, retain) IBOutlet UILabel                  *mailStatusMessage;
@property (nonatomic, retain) IBOutlet UIButton                 *shareButton;


//Scream Button
- (IBAction)    scream:                 (id) sender;

//Mail the scream
- (IBAction) showPicker:    (id)sender;
- (void)displayComposerSheet;
- (void)launchMailAppOnDevice;


@end

Here’s the top of .m:

#import "ScreamViewController.h"

//top of code has Audio session callback function for responding to audio route changes (from Apple's code), then my code continues...

@implementation ScreamViewController 

@synthesize appSoundPlayer;             // AVAudioPlayer object for playing the selected scream
@synthesize soundFileURL;               // Path to the scream
@synthesize interruptedOnPlayback;      // Was application interrupted during audio playback
@synthesize playing;                    // Track playing/not playing state


@synthesize screamButton;               //Press this button, girls scream.
@synthesize screams;                    //Mutable array holding strings pointing to sound files of screams.
@synthesize personScreaming;            //Mutable array tracking the person doing the screaming
@synthesize photoArray;                 //Mutable array holding strings pointing to photos of screaming girls
@synthesize personScreamingField;       //Field updates to announce which girl is screaming.
@synthesize personScreamingImage;       //Updates to show image of the screamer.
@synthesize funnyButtonSayings;         //Mutable array holding the sayings
@synthesize funnyButtonSayingsLabel;    //Label that updates with the funnyButtonSayings


@synthesize mailStatusMessage;          //did the email go out
@synthesize shareButton;                //share scream via email

Next line begins the block with the offending code:

- (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;



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

        //Log the string to the console
        NSLog (@"displaying photo: %@", screamerPic);

        // Display the image of the person screaming
        personScreamingImage.image = [UIImage imageNamed:screamerPic];

        //show the share button
        shareButton.hidden = NO;

        mailStatusMessage.hidden = NO;
        mailStatusMessage.text = @"share!";



        //Get the string at the index in the funnySayings array
        currentSayingsIndex = random() % [funnyButtonSayings count];
        currentButtonSaying = [funnyButtonSayings objectAtIndex: currentSayingsIndex]; 

        NSString *theSaying = [funnyButtonSayings objectAtIndex:currentSayingsIndex];
        [funnyButtonSayingsLabel setText: theSaying];

        currentScreamIndex++;



    }
}

Here’s my dealloc:

- (void)dealloc {
    [appSoundPlayer stop];
    [appSoundPlayer release], appSoundPlayer = nil;
    [screamButton release], screamButton = nil;
    [mailStatusMessage release], mailStatusMessage = nil;
    [personScreamingField release], personScreamingField = nil;
    [personScreamingImage release], personScreamingImage = nil;
    [funnyButtonSayings release], funnyButtonSayings = nil;
    [funnyButtonSayingsLabel release], funnyButtonSayingsLabel = nil;
    [screams release], screams = nil;
    [personScreaming release], personScreaming = nil;
    [soundFileURL               release];

    [super dealloc];
}


@end

Thanks so much for reading this far! Any input appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:57:08+00:00Added an answer on May 15, 2026 at 9:57 am

    It is possible this is a red herring from the Leaks tool. See this post in dev forums: https://devforums.apple.com/message/119423#119423
    I “detect” the same leak in the leaks tool in my implementation of an AVAudioPlayer and am pretty sure my code is correct (mainly because it is so simple).
    Here’s the actual expert commentary; he’s talking about 3.5k detected at [NSThread start] and we have here a 3.5k [CAPThread::Start()], but I think we’re in the same boat:

    “The issue is that the 3.5K you see is basically a data structure needed for the Kernel to track a thread. This data structure will be freed eventually, but once the thread is terminated there is no longer a reference to it in your process space (only in the kernel).”

    I hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This part of an app that I am working on, I have the following
I have been putting off developing this part of my app for sometime purely
I have a web app that needs both functionality and performance tested, and part
I have multiple app processes that each connect to servers and receive data from
I'm writing an app to help facilitate some research, and part of this involves
This module is part of a simple todo app I made with Python... def
Im developing a rails app. Following this tutorial here: Tutorial I finished a part
I have this part in a method, It should return the page and headers
I have this part of the function : $jQ('.product-collateral .product-tabs li').each(function(index){ $jQ(this).attr('id', $jQ(this).find('h3').attr('class')); if(index
I have this part of code in my functions.php: function cc_admin_enqueue_scripts($hook) { $file_dir=get_bloginfo('template_directory'); wp_enqueue_script('media-upload');

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.