Re: observing dealloc
Re: observing dealloc
- Subject: Re: observing dealloc
- From: Chris Suter <email@hidden>
- Date: Tue, 29 May 2007 14:28:30 +1000
On 29/05/2007, at 2:08 PM, Ken Tozier wrote:
On May 28, 2007, at 11:28 PM, Chris Hanson wrote:
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.
Let me see if I have this right. Given two classes "MyBaseClass"
and MySubClass
@interface MyBaseClass : NSObject
@end
@implementation MyBaseClass
NSMutableDictionary gGlobals = nil;
+ (void) initialize
{
if (gGlobals == nil)
{
gGlobals = [[NSMutableDictionary alloc] init];
}
}
@end
@interface MySubClass : MyBaseClass
@end
MyBaseClass *a = [[MyBaseClass alloc] init];
MySubClass *b = [[MySubClass alloc] init];
The "gGlobals" variable for "a" would be distinct from the
"gGlobals" for "b" correct?
No.
As others have suggested, why don't you just do something like the
following?
+ GlobalVarType *)globalVar
{
static GlobalVarType *globalVar;
if (!globalVar)
globleVar = [[[GlobalVarType alloc] init];
return globalVar;
}
This obviously isn't thread-safe; you'd have to add any thread safety
you might want.
Trying to generalise this would be just making things more
complicated for no real gain.
- Chris
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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