Objective - C直接初始化(对于Cocos2D风格的动作)
我有一个类的初始化如下:
@implementation MyClass
+(id) initializeMyClass
{
return [[[self alloc] initMyClass] autorelease];
}
-(id) initMyClass
{
if (([self = [super init]))
{
}
return self;
}
-(void) dealloc
{
NSLog(@"Deallocating");//I also used CCLOG instead.
[super dealloc];
}
@end
我在另一个没有对象的类中初始化这个类:
[MyClassinitializeMyClass];
这工作正常,但 MyClass 的 dealloc 方法没有被调用并且崩溃,因为某些资源被没有被释放。
这完全令人费解,在网上找不到任何东西。 如果有人提出解决方案或替代方法,我将非常感激。
谢谢。
I have a class with initialization as follows:
@implementation MyClass
+(id) initializeMyClass
{
return [[[self alloc] initMyClass] autorelease];
}
-(id) initMyClass
{
if (([self = [super init]))
{
}
return self;
}
-(void) dealloc
{
NSLog(@"Deallocating");//I also used CCLOG instead.
[super dealloc];
}
@end
I initialize this class in another class without an object:
[MyClass initializeMyClass];
This works fine but the MyClass' dealloc method is not called and crashes since some resources are not freed.
This is totally puzzling and can't find anything online.
If anyone would suggest a solution or an alternative method, i'd really appreciate it.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要将 MyClass 初始化为另一个类,那么您应该这样写
if you need to initialize your MyClass into another class then you should write like