我只是无法弄清楚这个保留周期,并希望如果有人能帮我发现它。Cocos2d代表保留周期
我有一个RootController
对象,强烈指出RootView
。
@interface RootController : CCNode <TouchDelegate, GUIDelegate, ModelViewDelgate>
...
@property (nonatomic, weak) CCDirector *director;
@property (nonatomic) RootView *view;
...
@end
@implementation
- (id)init {
...
_view = [[RootView alloc] initWithController:self];
[self addChild:_view];
...
}
return self;
}
@end
我有一个RootView
对象保持到所述控制器的参考,以及一个activeGame
,使我的游戏类型之间切换,而无需知道其他的细节比它符合一<TouchDelegate>
协议:
@interface RootView : CCScene
...
@property (nonatomic, assign) RootController *controller;
@property (nonatomic) GameplayLayer <ModelViewDelgate> *activeGame;
...
@end
@implementation RootView
- (id)init {
...
self.activeGame = [[GameplayLayer alloc] initWithDelegate:_controller root:self type:type];
[self addChild:self.activeGame];
...
}
return self;
}
@end
最后,我有GameplayLayer,这是必要的,当RootView调用,应该由RootView被释放:
@interface GameplayLayer : CCLayer <ModelViewDelgate, Updatable>
...
@property (nonatomic, assign) RootView *rootView;
@property (nonatomic, assign) RootController <TouchDelegate> *touchDelegate;
...
@end
当一个控制器类决定清理游戏的时候(通常是游戏的硬重置),我的项目中的其他任何类都会被释放,除了这个GameplayLayer,它永远不会接收到dealloc方法。我错过了什么?下面是我“重新启动”我的游戏...
[[CCDirector sharedDirector] replaceScene:[RootController node]];
你在'RootView'的'dealloc'中发布'GameplayLayer'吗? – 2013-04-30 00:39:05
我将'_activeGame.touchDelegate','_activeGame.rootView'和'_activeGame'设置为nil。 – Clev3r 2013-04-30 00:47:21
“self.activeGame = nil;'或'[_activeGame release];'。否则,你只是在指责,而不是破坏对象。或者(最佳答案),转换为ARC。 – 2013-04-30 00:48:52