• 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
RetainCount Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RetainCount Question


  • Subject: RetainCount Question
  • From: Mail5 <email@hidden>
  • Date: Thu, 26 May 2005 11:40:58 -0400

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: RetainCount Question
      • From: Shawn Erickson <email@hidden>
    • Re: RetainCount Question
      • From: Rick Kitts <email@hidden>
  • Prev by Date: Re: Xcode-users Digest, Vol 2, Issue 224
  • Next by Date: Re: RetainCount Question
  • Previous by thread: Re: Xcode-users Digest, Vol 2, Issue 224
  • Next by thread: Re: RetainCount Question
  • Index(es):
    • Date
    • Thread