Re: observing dealloc
Re: observing dealloc
- Subject: Re: observing dealloc
- From: James Bucanek <email@hidden>
- Date: Tue, 29 May 2007 11:07:15 -0700
Wincent Colaiuta <mailto:email@hidden> wrote (Tuesday, May
29, 2007 8:32 AM +0200):
Although Apple's docs indicate that the runtime will send the
initialize message once per class, that doesn't mean that the test in
the above code is pointless. As the example code below demonstrates,
the super class initialize method will be called for subclasses if
they don't implement it, which means that the same static variable can
end up getting used in both cases. Also, even though the docs say that
you "typically" don't need to call +[super initialize], there are
plenty of examples of code out in the wild which do exactly that and
so you may need to be aware of that also if you're writing frameworks
or code which may be used by others.
You're correct for the more complex cases. The point I was
trying to make is that the original poster is creating an overly
complicated solution where a simple one will do.
Example:
#import <Foundation/Foundation.h>
@interface Foo : NSObject {}
@end
@implementation Foo
+ (void)initialize
{
static int count = 0;
NSLog(@"+[%@ initialize]: %d", NSStringFromClass([self class]), count++);
}
@end
<clip>
And in the interests of simplification:
NSLog(@"+[%@ initialize]: %d", [self className], count++);
:)
--
James Bucanek
_______________________________________________
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