我有一個名爲Hexagon
的自定義類,它是NSObject
的子類。但是,當我將它分配給一個精靈並通過調用-addChild:
將其添加到屏幕中時,它的保留計數爲2!我該怎麼做才能阻止這種泄漏?通過調用addChild泄漏對象
for (int i =0; i < HEXCOUNT; i++){
Hexagon *nHex = [[Hexagon alloc]initWithDicitonary:hexPositions];
CCSprite *theSprite = (CCSprite*)nHex;
NSString *hexName = [NSString stringWithFormat:@"hexagon%d", i];
CGPoint location = CGPointFromString([[EXHEXAGONS objectForKey:hexName]objectForKey:@"position"]);
CGPoint nLocation = ccp(screenSize.width/2 + 68 * location.x,screenSize.height/2 + 39 * location.y);
theSprite.position = nLocation;
[self addChild:theSprite z:1 tag:i];
NSMutableDictionary *hexProperties = [EXHEXAGONS objectForKey:hexName];
[hexProperties setObject:theSprite forKey:@"realSprite"];
[EXHEXAGONS setObject:hexProperties forKey:hexName] ;
[[GameStateSingleton sharedMySingleton]setExistingHexagons:EXHEXAGONS];
[nHex release];
}
'retainCount'是完全無用的。別叫它。 – bbum