• 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: Object Ownership
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Object Ownership


  • Subject: Re: Object Ownership
  • From: Dave Carrigan <email@hidden>
  • Date: Sat, 22 May 2010 10:13:55 -0700

On May 22, 2010, at 8:18 AM, Michael Jackson wrote:

> Hi all,
>
> First day with Cocoa, so please excuse the basic newbness of this
> question. ;) I've read through the documentation about object
> ownership and disposal and just wanted to make sure I'm doing
> everything correctly in the following method.
>
>
> - (NSURL *)makeURL:(NSString *)aURLString
> {
> 	NSMutableString *aCopy = [aURLString mutableCopy];
>
> 	// do some stuff with aCopy here
>
> 	NSURL *aURL = [NSURL URLWithString:aCopy];
> 	[aCopy release];
>
> 	return aURL;
> }
>
>
> The question is whether or not NSURL's URLWithString: is going to
> retain aCopy, so it's safe to be released on the next line. I'm just
> looking for some confirmation or any pointers from people who are more
> used to managing memory than I am.

This is fine. If NSURL needs to keep aCopy, it will retain it; if it doesn't, it will not. That's not your concern; only the implementor of NSURL needs to worry about that.

Your only concern is to release aCopy when you don't need it any more, which is what you are doing.


_______________________________________________

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

References: 
 >Object Ownership (From: Michael Jackson <email@hidden>)

  • Prev by Date: Object Ownership
  • Next by Date: Re: getting file creation date from NTFS
  • Previous by thread: Object Ownership
  • Next by thread: Re: Object Ownership
  • Index(es):
    • Date
    • Thread