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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:15:03+00:00 2026-06-05T13:15:03+00:00

I’m using Blocks in iOS5 with ARC to play a never ending cycle of

  • 0

I’m using Blocks in iOS5 with ARC to play a never ending cycle of audio recordings with AVAudioPlayer. I alloc a new AVAudioPlayer after receiving the AVAudioPlayerDidFinishRecording message, which starts a cycle of recursion. My app consistently crashes after 120 or so audio clips are played back. I can see that it uses up more and more memory as each audio file is loaded, but never releases the memory.

I’m using a single AVAudioPlayer property, so I was expecting ARC to clean up the old instances every time I alloc a new player.

  1. Could the blocks be somehow causing the old AVAudioPlayers to stick around?

  2. Would it be better to use an Observer to monitor the player and launch/alloc new players?

Thanks so much for your help!

-(void)playNextAudioItem{
    //get ready to load audio doc from iCloud
    NSURL *ubiquitousContainer = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
    if(ubiquitousContainer){
        //query iCloud
        query = [[NSMetadataQuery alloc]init];
        [query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];
        NSPredicate *pred = [NSPredicate predicateWithFormat:@"(%K == %@)", NSMetadataItemFSNameKey, [NSString stringWithFormat:@"%@.caf", audioItemGUID]];
        [query setPredicate:pred];
        [[NSNotificationCenter defaultCenter] addObserverForName:NSMetadataQueryDidFinishGatheringNotification object:query queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif){
            //iCloud query finished gathering data
            [query disableUpdates];
            [[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidFinishGatheringNotification object:query];
            NSMetadataItem *item1 = [query resultAtIndex:0];
            audioCurrentVerse = [[audioDoc alloc] initWithFileURL:[item1 valueForAttribute:NSMetadataItemURLKey]];
            //open the audio file
            [audioCurrentVerse openWithCompletionHandler:^(BOOL success) {
                if(success){
                    //configure the session and play the audio file
                    AVAudioSession *audioSession = [AVAudioSession sharedInstance];        
                    [audioSession setActive:YES error:nil];
                    NSError *error = nil;
                    [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
                    audioPlayer = [[AVAudioPlayer alloc] initWithData:audioCurrentVerse.data error:&error];
                    audioPlayer.numberOfLoops = 0;
                    audioPlayer.delegate = self;
                    if([audioPlayer prepareToPlay]){
                        [audioPlayer play];
                    }
                }
            }];
            [query stopQuery];
            query = nil;
        }];
        [query startQuery];
    }
}

-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
    //get an identifier for the next audio item
    audioItemIndex++;
    if(audioItemIndex >= rsAudioItems.recordCount){
        verseIndex = 0;
    }
    audioItemGUID = [rsAudioItems getRow:audioItemIndex andColumnNamed:@"audioItemGUID"];
    //recursive call to play the next audio item
    NSLog([NSString stringWithFormat:@"%d", playCount++]);
    [self playNextAudioItem];
}
  • 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-05T13:15:07+00:00Added an answer on June 5, 2026 at 1:15 pm

    Blocks take a snapshot of the stack that is not released until the block is freed. Don’t use recursive blocks (or really recursion at all, if it doesn’t really make sense in the situation) because the blocks never get freed so the snapshots stick around forever.

    Using a for loop would alleviate this issue. You could add them to a serial dispatch queue and then they’d be freed after execution.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want use html5's new tag to play a wav file (currently only supported
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.