I am working with ARC and Cocos2d 2.0 as static library (which does not use ARC and is compiled as a separate target). I translated an old project (made without ARC) and I am wondering whether declaring properties in this way has some potential retain cycle issue:
@interface PlayerData : NSObject <NSCoding> {
}
//Is ok to save this as if the game gets paused you may want to save this.
@property (readwrite, nonatomic) int numberOfHits;
@property (readwrite, nonatomic) bool everBeenHitInCurrentLevel;
@property (readwrite, nonatomic) int hitsForOneHearth;
I noticed that my various scenes build up memory over time. Also I added a CCLOG call in the release method of the CCLayer method (MyScene : CCLayer) and it never gets called. That's how I create the scene (which I replace using the "[CCDirector sharedDirector] replaceScene" method
+ (id) sceneWithLevelName:(LevelName)name
{
CCScene *scene = [CCScene node];
ShooterScene * shooterLayer = [[self alloc] initWithId:name];
[scene addChild:shooterLayer];
return scene;
}
EDIT: As I realized that I stupidly did NOT include an example with Objects and used only primitive data type I will here paste some snippets of elements in my scenes: CharacterSelection, ShooterScene and PlanetSelectionMenu:
//ShooterScene
@interface ShooterScene : CCLayer {
HudLayer * hudLayer;
....
}
@property(readwrite, nonatomic) CCSpriteBatchNode* backgroundAndEnemiesBatchNode;
@property(readwrite, nonatomic) ShipEntity* playerShip;
... etc..
Please note that I do not declare member variables for properties like playerShip and backgroundAndEnemiesBatchNode beause, as far as I can understand, should suffice the property declaration (but please correct me if I am wrong or if the approach may cause issues).
//CharacterSelectionScene
@interface CharacterSelectionScene : CCLayer {
int currentlySelectedCharacterSpriteTag;
CCSprite * lights;
CCLayer * spritesLayer;
...
}
//PlanetSelectionMenu
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface PlanetSelectionMenu : CCLayer {
CCLayer * backgroundLayer; // Added background images here
CCLayer * alwaysPresentItems;
}
+ (id) scene;
@end
Please note that each time I go from PlanetSelectionMenu to CharacterSelectionScene -and vice versa- memories increases. However in this case I have not used any properties but "just" added objects (CCSprites) to layers and batchnodes.
EDIT 2: Here is what I see in Allocation when running through Menu->CharacterSelection->PlanetSelectionScene etc.. it seem that on avarage the LiveBytes are 4MB and, as I see only one scene at the time then I assume that there are no retain cycles. Then why do I get those nasty LOW memory messages?
MyScene
? Do you think they should deallocated? – Aaron Brager