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 8596131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:36:13+00:00 2026-06-12T00:36:13+00:00

I am runung Instruments on an iPhone 4S. I am using AVAudioPlayer inside this

  • 0

I am runung Instruments on an iPhone 4S.
I am using AVAudioPlayer inside this method:

-(void)playSound{
    NSURL *url = [self.word soundURL];
    NSError *error;
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    if (!error) {
        [audioPlayer prepareToPlay];
        [audioPlayer play];
    }else{
       NSLog(@"Problem With audioPlayer on general card. error : %@ | url %@",[error description],[url absoluteString]);
}

I am getting leaks when playing the sound files:

Leaked objects:

1.

Object: NSURL

Responsible Library: Foundation

Responsable Frame: Foundation -[NSURL(NSURL) allocWithZone:]

2.

Object: _NSCFString

Responsible Library: Foundation

Responsable Frame: Foundation -[NSURL(NSURL) initFileURLWithPath:]

Instruments does not point directly to my code so I find it hard to locate the leak reason.

MY QUESTION

What could cause the leak?
OR How can I locate leaks when I am not responsible to the code?

EDIT
This is the schema from Instruments cycles view:
enter image description here
Thanks Shani

  • 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-06-12T00:36:14+00:00Added an answer on June 12, 2026 at 12:36 am

    Looks to be a leak in Apple’s code… I tried using both

    • -[AVAudioPlayer initWithData:error:] and
    • -[AVAudioPlayer initWithContentsOfURL:error:]

    In the first case, the allocated AVAudioPlayer instance retains the passed in NSData. In the second, the passed in NSURL is retained:

    I’ve attached some screen shots of the Instruments window showing the retain/release history for a passed in NSData object.

    enter image description here

    You can see the AVAudioPlayer object then creates a C++ object AVAudioPlayerCpp, which retains the NSData again:

    enter image description here

    Later, when the AVAudioPlayer object is released, the NSData is released, but there’s never a release call from the associated AVAudioPlayerCpp… (You can tell from the attached image)

    Seems you’ll have to use a different solution to play media if you want to avoid leaking NSData/NSURL’s..

    Here’s my test code:

    -(void)timerFired:(NSTimer*)timer
    {
        NSString * path = [[ NSBundle mainBundle ] pathForResource:@"song" ofType:@"mp3" ] ;
    
        NSError * error = nil ;
        NSData * data = [ NSData dataWithContentsOfFile:path options:NSDataReadingMapped error:&error ] ;
        if ( !data )
        {
            if ( error ) { @throw error ; }
        }
    
        AVAudioPlayer * audioPlayer = data ? [[AVAudioPlayer alloc] initWithData:data error:&error ] : nil ;
        if ( !audioPlayer )
        {
            if ( error ) { @throw error ; }
        }
    
        if ( audioPlayer )
        {
            [audioPlayer play];
            [ NSThread sleepForTimeInterval:0.75 ] ;
            [ audioPlayer stop ] ;
        }
    }
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // ...
        [ NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector( timerFired: ) userInfo:nil repeats:YES ] ;
        // ...
        return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanna build a client server iphone app and for this i need to
I am trying to setup Jeash for Haxe, so I read this: http://old.haxe.org/com/libs/jeash/firststeps Now,
I am working on the equals() method for my sparse matrix class that I'm
What is the optimal amount of lines in method shold be used? Curly braces
Hi I am using a custom model binder with asp.net mvc 2.0 , everything
I am getting this error whenever my S#arp Architecture attempts to start and this
Currently I'm experimenting with this code (I know it doesn't fit the purpose). I
this is probably something I should know, but I'm puzzled by this. I'm trying
Using async for threads in perl script I need to do some parallel functionality,
I had this error when runing the Android project: com.android.ddmlib.AdbCommandRejectedException: device not found at

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.