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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:48:29+00:00 2026-05-26T16:48:29+00:00

Not sure if this is a simulator issue or I am missing something, the

  • 0

Not sure if this is a simulator issue or I am missing something, the following code gives me a memory leak although theAudio is released as in dealloc. I am playing a .wav file and the sound will change depending on the value of an integer. The App runs ok but 16 bit leak is flagged whwn I test this in xcode

Any suggestion is greatly appreciated:

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface Water : UIViewController 
<AVAudioPlayerDelegate>

{

}

@property (nonatomic,retain) AVAudioPlayer *theAudio;


-(IBAction) goButMenu: (id) sender;
-(IBAction) goDrinkMenu: (id) sender;
-(IBAction) playwater;


@end



@implementation Water
@synthesize theAudio;

-(IBAction) goDrinkMenu: (id) sender{

ButDrinkMenu *butdrinkmenu1 = [[ButDrinkMenu alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:butdrinkmenu1 animated:YES];

}

-(void) viewDidLoad {

if (BoyOrGirl == 1) {

    NSString *path = [[NSBundle mainBundle] pathForResource:@"Applause" ofType:@"wav"];
    theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate = self;
    [theAudio play];


}

else {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"bongo" ofType:@"wav"];

    theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate = self;
    [theAudio play];

}





}

-(IBAction) playwater{

if (BoyOrGirl == 1) {

    NSString *path = [[NSBundle mainBundle] pathForResource:@"Applause" ofType:@"wav"];
    theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate = self;
    [theAudio play];




}

else {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"bongo" ofType:@"wav"];
    theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate = self;
    [theAudio 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-26T16:48:29+00:00Added an answer on May 26, 2026 at 4:48 pm

    Definitely test on the device directly; testing for leaks with the simulator may return inaccurate results.

    That said, there are several memory-related concerns with this code sample. You may wish to include your dealloc method here as that may offer some insight, but here’s a problem (that appears in several of your allocations):

    Your AVAudioPlayer isn’t being assigned to your property, nor is it being released in scope. Ideally a player allocation would look more like:

    AVAudioPlayer *myPlayer = [[AVAudioPlayer alloc] initWithContents....
    [myPlayer setDelegate:self];
    [self setTheAudio:myPlayer];
    [myPlayer release];
    

    As opposed to how you’ve implemented it, which assigns the player directly the instance variable:

    theAudio = [[AVAudioPlayer alloc] initWith...
    

    Because you assign the player directly to your instance variable, your player isn’t being retained. This is likely to result in either premature release and a dangling pointer if you try and balance your calls properly, or it will result in leaking.

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

Sidebar

Related Questions

This code works on simulator but not on device. I am positive this has
Not sure this is a programming question, but we use LaTeX for all our
Not sure this is possible, but looking to write a script that would return
I'm not sure this is possible, but in ruby, you can dynamically call a
I'm not sure this is possible, but is there a syntax to be used
I'm still not sure this is the correct way to go about this, maybe
I am pretty sure this is possible just not sure what is the term
I'm sure this is a fairly trivial problem, but I'm not sure what to
First of all I'm not sure this is even possible, however I need to
Ok I'm working on getting better with python, so I'm not sure this is

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.