Re: observing dealloc
Re: observing dealloc
- Subject: Re: observing dealloc
- From: Chris Hanson <email@hidden>
- Date: Mon, 28 May 2007 20:28:48 -0700
On May 28, 2007, at 4:49 PM, Ken Tozier wrote:
On May 28, 2007, at 7:44 PM, Steve Israelson wrote:
What is wrong with having static variables in your class
implementation file?
Then use class methods to access em, and put any threading stuff in
there too.
You can even have a global to count how many object of your class
are created.
That's exactly what this does only in a standardized way. Maybe the
word "global" is confusing the issue. Perhaps I should have used
"static variable."
What you're talking about are called "class variables" -- variables
owned by the class itself, rather than by individual instances of the
class.
One further distinction to make is whether you're dealing with true
"class variables" or with "class instance variables." A class can be
thought of as just another object; a class instance variable is an
instance variable of the class object. The difference between the two
is that if you have class A and class B which is a subclass of A, they
each share the *same* class variables but because each class is a
distinct object they each get *their own copy* of each class instance
variable.
Of course, Objective-C doesn't have any syntax for either class
variables or class instance variables, so if you want the
functionality you'll have to implement it yourself. (And you'll have
to do things like consider the threading implications -- which really
*don't* go away if you "just" want to read data, unfortunately.)
Greg Titus is right, too -- regardless of whether you're talking about
class variables or class instance variables, they should live for the
lifetime of the class itself, rather than the lifetime of any
instances of the class. So worrying about releasing objects referred
to by class variables or class instance variables when the last
instance of a class goes away is probably excessive.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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