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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:51:19+00:00 2026-05-21T21:51:19+00:00

I am using AVAudioPLayer to do the audio for my game. I have the

  • 0

I am using AVAudioPLayer to do the audio for my game. I have the following code in a method in a seperate class, which is called every time I want the ‘boing’ sound to play. Problem is, it leaks huge amounts of memory, to the point where the game becomes unplayable. Now i’m not releasing any of the pointers in the method, because at the time I only had one. But now I have 10 of these methods.

What is the best way to release the pointers in tis case? (Yes, I have tried releasing straight after [boing play];, this solves the leak (obviously) but the sound dosen’t play so theres no point.

    -(void)playBoing {
        int x = (arc4random()%3)+1;
        NSString *path = [NSString stringWithFormat:@"/boing_0%i.aif", x];

        NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
        resourcePath = [resourcePath stringByAppendingString:path];

        AVAudioPlayer *boing = [[AVAudioPlayer alloc] initWithContentsOfURL:
                                [NSURL fileURLWithPath:resourcePath] error:nil];

        boing.delegate = self;
        boing.volume = 1;

        [boing play];
}
  • 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-21T21:51:20+00:00Added an answer on May 21, 2026 at 9:51 pm

    It’s possible there’s a better solution, but I’ve had similar problems where releasing right away killed my process. This is the solution I took. Again, there may be better out there, but for a quick fix, it should do the trick.

    In your header file, create the following:

    AVAudioPlayer *boing;
    

    Then in -(void)playBoing, do as you did, but change

    AVAudioPlayer *boing = [[AVAudioPlayer alloc] initWithContentsOfURL:
                            [NSURL fileURLWithPath:resourcePath] error:nil];
    

    to

    if (boing != nil) {
        boing = nil;
        [boing release];
    }
    boing = [[AVAudioPlayer alloc] initWithContentsOfURL:
             [NSURL fileURLWithPath:resourcePath] error:nil];
    

    This should ensure that there’s only one instance of boing allocated at a time

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

Sidebar

Related Questions

I have been using a class to play sounds using AVAudioPlayer. Since I want
I am using the following code to play a audio in iOS using **AVAudioPlayer**
I have an Audio app using AVAudioPlayer on iOS. Whenever music is playing my
I am streaming a MP3 over network using custom feeding code, not AVAudioPlayer (which
Alright I have two problems. I'm using AVAudioPlayer to play a simple audio file
i have converted my .caf audio file to NSData object using the following line
I have got an audio file which is quite quiet. I'm playing it using
I am using AVAudioplayer to play some audio files. I have some controls like
I'm playing an audio clip using a UIButton that calls a method (see code
I am using multiple instances of AVAudioPlayer to play multiple audio files simultaneously. I

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.