• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: leak in a sound function
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: leak in a sound function


  • Subject: Re: leak in a sound function
  • From: Agha Khan <email@hidden>
  • Date: Sun, 23 Aug 2009 11:37:26 -0700

Thank you All.
I came from Windows and this is my first project with Objective-C.

I am looking Mac provided file SoundEngine.cpp about line 770
OSStatus LoadTrack(const char* inFilePath, Boolean inAddToQueue, Boolean inLoadAtOnce)


I realized we are creating pointer to BG_FileInfo pointer and never released when we again allocating same pointer. That is a leak. So I changed from
BG_FileInfo *fileInfo = new BG_FileInfo;
to
static BG_FileInfo *fileInfo = NULL;

if (fileInfo != NULL)
{
delete fileInfo;
fileInfo = NULL;
}

fileInfo = new BG_FileInfo;


Now there is no leak. :-)

I also tried NSBundle* bundle = [[NSBundle mainBundle] retain];

but leak was still there.

All comment are appreciated.

Need more comments what I did is correct.

Best regards
Agha




On Aug 23, 2009, at 11:17 AM, Kyle Sluder wrote:

On Aug 23, 2009, at 9:53 AM, Agha Khan <email@hidden> wrote:

+ (void) PlaySound:(int) Index

Method names should begin with lowercase letters. Classes really are the only things in ObjC that are typically capitalized.


Also you should be using the NSUInteger typedef here.

  NSBundle* bundle = [NSBundle mainBundle];

 …

[bundle release];

You need to reread the memory management documentation again. You didn't get the bundle through alloc, new, or copy, and there you don't own it and mustn't release it.


--Kyle Sluder


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: leak in a sound function
      • From: "Sean McBride" <email@hidden>
    • Re: leak in a sound function
      • From: Mohsan Khan <email@hidden>
    • Re: leak in a sound function
      • From: Agha Khan <email@hidden>
References: 
 >leak in a sound function (From: Agha Khan <email@hidden>)
 >Re: leak in a sound function (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Running shell scripts as root.
  • Next by Date: Re: Making an NSTableView Display Articles From An RSS Feed.
  • Previous by thread: Re: leak in a sound function
  • Next by thread: Re: leak in a sound function
  • Index(es):
    • Date
    • Thread