I have a class called NSMyNumber.(if you want to see why I did it, http://www.cocos2d-iphone.org/forum/topic/1481 )
The source code is the following:
@implementation NSMyNumber
@synthesize intValue;
+(id) numberWithInt:(int) _value
{
return [[self alloc] initWithInt:_value];
}
- (id) initWithInt:(int) _value
{
if(self = [super init])
{
intValue = _value;
}
return self;
}
@end
This program has any problem except for one thing. It runs, doesn't crash, but is going to keep leaking memory since I'm not autoreleasing the momory allocated in numberWithint function. However, my game crashes if I add autorelease code there like CocosNode: return[[[self alloc] initWithInt:_value]autorelease];
New questions : Why does it crash?
Exception is BAD_ACCESS and function call hierarchy is the following:
0 objc_msgSend
1 NSPopAutoreleasePool
2 _UIApplicationHandleEvent
3 PurpleEventCallback
....
....
But my code is almost identical to CocosNode?..