• 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: DairyKnight <email@hidden>
  • Date: Fri, 21 Aug 2009 17:08:58 +0800

One more thing, it has nothing to do with the DateFormatter. So somehow
UIDatePicker released its date somewhereoutside of my code... I guess it has
something to do with autoreleasepool.

On Fri, Aug 21, 2009 at 5:07 PM, DairyKnight <email@hidden> wrote:

>
> OK. Here's the code of my UIViewController:
>
> - (void)viewDidLoad {
>
>     [super viewDidLoad];
>
>  okButton = [[UIBarButtonItem alloc] initWithTitle:@"OK" style:
> UIBarButtonItemStyleBordered   target:self   action:@selector(okAction:)];
>
> self.navigationItem.rightBarButtonItem = okButton;
>
> [okButton release];
>
> [self.view setBackgroundColor:[UIColor blackColor]];
>
>  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
>
> [dateFormatter setDateFormat:@"H : m"];
>
> NSDate *date = [dateFormatter dateFromString:@"0 : 0"];
>
> [picker setDate:date];
>
> [dateFormatter release];
>
> }
>
> and if you click on the button, in
> -(void) okAction:(id) sender
>
> {
> }
> the Reference count of 'date' is somehow mystically decreased by 1. There's
> no other code in the message
> loop, and what I did was directly press the button on the View.
>
>
>
> On Fri, Aug 21, 2009 at 3:38 PM, Graham Cox <email@hidden>wrote:
>
>>
>> On 21/08/2009, at 5:32 PM, DairyKnight wrote:
>>
>>  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?
>>>
>>
>>
>> This should work OK, so if it's crashing, you have a bug elsewhere.
>>
>> Once you are no longer interested in an object, you are free to release
>> it. Another object that needs to keep it will retain it.
>>
>> --Graham
>>
>>
>>
>
_______________________________________________

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

  • Prev by Date: Re: When do I need to override hash?
  • Next by Date: core data nsarraycontroller for all entities
  • Previous by thread: Re: When to 'release' in Cocoa management?
  • Next by thread: Re: When to 'release' in Cocoa management?
  • Index(es):
    • Date
    • Thread