Re: Memory Management Mismanaged
Re: Memory Management Mismanaged
- Subject: Re: Memory Management Mismanaged
- From: Marcel Weiher <email@hidden>
- Date: Thu, 8 May 2003 23:15:27 +0200
+ (MyFoo*) myFoo
{
MyFoo* aFoo = [[[myFoo alloc] init] autorelease];
return aFoo;
}
+myFoo
{
return [[[self alloc] init] autorelease];
}
Can you provide an example of how the first example breaks in a
sub-class?
Example:
@interface MyFoo : NSObject {}
+(MyFoo*)myFoo;
@end
@interface MyBar : MyFoo {}
-(void)someMethodOnMyBar;
@end
....
[[MyBar myFoo] someMethodOnMyBar];
/*Compiler will complain, because return type of myFoo is (MyFoo*),
and MyFoo doesn't respond to -someMethodOnMyBar*/
The compiler complaining is one of the problems (the one caused by the
static type). However, due to actually naming the class, instead of
using self, this will actually fail at runtime, because you will be
getting an instance of the superclass. Hmm...coming to think of it:
in that case, the compiler warning is, of course, actually correct..
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.