Re: NSCalendarDate loses retain count [Solved confusion]
Re: NSCalendarDate loses retain count [Solved confusion]
- Subject: Re: NSCalendarDate loses retain count [Solved confusion]
- From: Brant Vasilieff <email@hidden>
- Date: Fri, 26 Oct 2001 10:36:25 -0700
Kurt,
Thanks. Your response did help.
I was looking inside the object in the debugger, and seeing the private
refCount member. After calling [[NSCalendarDate alloc] init] or
[NSCalendarDate calendarDate] it was zero, when calling retain it went
from zero to 1. When exiting the pool it went to zero. Calling retain
twice on retainedCalendarDate2 within the pool caused it to go to 2.
It was an easy mistake to make. The mechanism is often called reference
counting, so when I saw the refCount variable, I assumed it was the one
used by retain/release. When ever I've implemented reference counting,
that's what I called it. Watching it move up and down added to that
confusion.
There is indeed another member called retainCount that every object has,
and after adding the logs can verify that it doesn't prematurely fall to
zero.
After working for 14 hours, it was an easy mistake to make. What's
worse is that I spent probably another 2-3 hours trying to figure out
why I could still get the description of the objects even though they
appeared to have a retain count of zero.
I'm curious why NSCalendarDate has an extra tracking refCount, when it
appears that retainCount would do.
Thanks again,
Brant
On Friday, October 26, 2001, at 04:15 , Kurt Revis wrote:
How are you determining that the retain count is 0? Are you using
[object retainCount] or something else?
Calling [[NSCalendarDate alloc] init] or [NSCalendarDate calendarDate]
both return calendar dates with a refCount of zero.
I assume by "refCount" you mean "retainCount". And no, they don't. The
first case gives you an object whose retain count is 1. The second case
also gives you an object whose retain count is 1. (But that object is
also autoreleased, so when the autorelease pool is deallocated later,
the object will get released again and deallocated as well).