• 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: When to 'release' in Cocoa management?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When to 'release' in Cocoa management?


  • Subject: Re: When to 'release' in Cocoa management?
  • From: bryscomat <email@hidden>
  • Date: Fri, 21 Aug 2009 02:42:18 -0500

Yes. You release the object when one of three things occur:

1. You allocate the object yourself with the "alloc" message.
2. You allocate the object yourself with the shorthand "new" message.
3. You issue a retain message.

So in both examples you gave you are required to release the object, as you are responsible for it because you explicitly allocated it.

On Aug 21, 2009, at 2:32 AM, DairyKnight wrote:

Hi,
In some calls to Cocoa API subroutines we do:

UIView *myView = [[UIView alloc] init];
[window addSubView:myView];
[myView release];

but sometimes you cannot release the temporarily allocated object, e.g. :


UIDatePicler *picker;

... (picker was initialised somewhere)


NSDate *date = [[NSDate alloc] init];
[picker setDate:date];
[date release]; // Opps! immediate release of 'date' causes program crash.



So is there a rule of thumb, like when should we release immediately after
passing the object to some Cocoa API calls?


Thanks.

Regards,
DairyKnight
_______________________________________________

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

_______________________________________________

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: When to 'release' in Cocoa management?
      • From: Graham Cox <email@hidden>
References: 
 >When to 'release' in Cocoa management? (From: DairyKnight <email@hidden>)

  • Prev by Date: Re: When to 'release' in Cocoa management?
  • Next by Date: Re: Authorization Question (Possibly a simple POSIX question?)
  • Previous by thread: Re: When to 'release' in Cocoa management?
  • Next by thread: Re: When to 'release' in Cocoa management?
  • Index(es):
    • Date
    • Thread