• 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: Memory Management issue?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory Management issue?


  • Subject: Re: Memory Management issue?
  • From: Andrew Wadycki <email@hidden>
  • Date: Sat, 24 Sep 2005 10:17:16 -0500


On Sep 24, 2005, at 10:06, Aaron Wallis wrote:

Hi all,

im having some trouble with some code.

NSString * scriptPath = [[NSString alloc] init];
scriptPath = [[NSBundle mainBundle] pathForResource: @"someScript" ofType: @"scpt"];


// check to see if the file exists
if ( scriptPath != nil )
{
// create a url for the file
NSURL * scriptURL = [[ NSURL alloc ] init];
scriptURL = [NSURL fileURLWithPath: [NSString stringWithString:scriptPath]];


        // release the path
        [ scriptPath release ];
    }

Basically, im creating a string to build a path... if I comment the [scriptPath release]; line the script works 100%, if I leave it there I get a SIGSEGV 11 error...

im still kinda a newbie at Cocoa so im not to sure if im on the right track or not...
Any ideas?

You have overwritten the scriptPath string that you create with the alloc when you called pathForResource. The NSString returned from the pathForResource has an effective 0 retain count. Since you didn't call retain you don't have to release. You would be leaking the original scriptPath string you created. Skip the alloc and init since you are not using that string and drop the release and everything should work just fine.


-Andrew
------------------------------------------------------------------------ --
"Deep in the unconscious is a pervasive need for a logical
universe that makes sense. But the real universe is always
one step beyond logic." -Paul "Muad'Dib" Atriedes
------------------------------------------------------------------------ --



Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Memory Management issue? (From: Aaron Wallis <email@hidden>)

  • Prev by Date: Re: Memory Management issue?
  • Next by Date: Re: Memory Management issue?
  • Previous by thread: Re: Memory Management issue?
  • Next by thread: Re: Memory Management issue?
  • Index(es):
    • Date
    • Thread