I believe you were also on the discussion of properties vs. direct ivar access. 
This ties into that discussion. If you declare/define a property with:

@property (nonatomic, retain) NSDate* firstBadAccuracyTime;

and

@synthesize firstBadAccuracyTime=_firstBadAccuracyTime;

then the runtime will automatically retain the value in the setter, allowing 
you to make a call:

self.firstBadAccuracyTime = [NSDate date];

You would still need to release the object in dealloc

[_firstBadAccuracyTime release]

If you are using ARC, the property would be

@property (nonatomic, strong) NSDate* firstBadAccuracyTime;

the synthesize and set statements would be the same, but you would not be 
required to make the release call in dealloc. By using direct ivar access, you 
are taking the responsibility to handle the memory management yourself, meaning 
you really need to understand autorelease pools (see references in other posts).

Aaron

On Mar 17, 2012, at 3:38 PM, G S wrote:

> I have a member variable to hold an NSDate:
> 
>    NSDate* _firstBadAccuracyTime;
> 
> At some point, something happens and I set this value to "now":
> 
>    _firstBadAccuracyTime = [NSDate date];
> 
> On my next trip through this function, I calculate how long it has been
> since I set this date:
> 
>    NSDate* now = [NSDate date];
>    if([now timeIntervalSinceDate:_firstBadAccuracyTime] >
> BAD_ACCURACY_TIME)
> 
> then CRASH: BAD ACCESS
> 
> _firstBadAccuracyTime still contains a valid address, but the object
> must've been released.  Why?  If I add a retain where I assign it, the
> crash doesn't happen.  I added autorelease, but then got a crash on
> releasing an object I hadn't allocated (which makes me think it's already
> autoreleased).
> 
> Thanks for any insight!
> 
> Gavin
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/eeyore%40monsterworks.com
> 
> This email sent to eey...@monsterworks.com
> 


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to