Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RetainCount Question



It's in an autorelease pool?

---Rick

On May 26, 2005, at 8:40 AM, Mail5 wrote:

Lets say I have a simple method...

method.h ...

@interface Method : NSObject {
     NSDate        *date;
}
-(id)init;
-(void)setNewDate:(NSDate *)date;

@end

method.m ...

@implementation Method

//Init Methods
-(id)init
{
self = [super init];
date = [[NSDate dateWithTimeIntervalSinceReferenceDate:0] retain]; <<< see below for question
return self;
}
-(void)setNewDate:(NSDate *)newDate
{
[NewDate retain];
[date release];
date = newDate;
}
@end



Question:
The line ....
date = [[NSDate dateWithTimeIntervalSinceReferenceDate:0] retain];
date must be retained, yet, retaining it, sets the retain count to 2.


This does not make sense to me. Why should the retain count have to be 2?
As only one object references date.



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/xcode-users/rkitts% 40loudhouse.org


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden
References: 
 >RetainCount Question (From: Mail5 <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.