I am having difficulty locating a memory leak. I am using cocos2d. This is the data area for two classes:
@interface Dungeon : CCLayerColor {
DungeonLevel *aDungeonLevel;
Player *thePlayer;
// list of all monster file names
NSMutableArray *monsterNames;
// array of how many monsters there are of each monster level
NSMutableArray *monsterLevels;
MessageView *theMessageView;
DungeonDisplay *theDisplay;
bool processing;
int currentDungeonLevel;
}
@interface DungeonDisplay : CCLayerColor {
NSMutableArray *displayGrid;
NSMutableArray *displayGrid2;
NSMutableArray *displayGrid3;
NSMutableArray *displayGrid4;
NSMutableArray *dungeonMatrix;
NSMutableArray *monsterSprites;
Dungeon *theDungeon;
int xdelt;
int ydelt;
CGPoint lowerLeft;
Player *thePlayer;
CCSprite *playerSprite;
CCSprite *mSprite1;
ButtonsLayer *buttonArea;
double previousTime;
double currentTime;
double touchTimePrev;
bool touchFlag;
bool processing;
bool processing2;
bool animating;
bool flipSprite;
bool doIdleAnimation;
bool isAttacking;
int firstIteration;
CGPoint dungeonOriginalPosition;
CGPoint playerOriginalPosition;
CGPoint mSprite1Original;
CGPoint buttonOriginal;
CCTimer *myTimer;
// List of Messages
NSMutableArray *messages;
int messageIndex;
// player transparency level
int transparency;
// indicates that walls need to become transparent
bool needTransparency;
int pXInc;
int pYInc;
int tempx;
int tempy;
// debugging variables
CCLabelTTF *debugLabel1;
CCLabelTTF *debugLabel2;
// the Map
MiniMap *aMap;
}
Okay, now the Dungeon object creates the DungeonDisplay object by interacting with another object, DungeonLevel (I don’t think it is particularly relevant to figuring out why DungeonDisplay is not deallocated). This is all the code for creation of the “singleton” DungeonDisplay object:
-(void) displayDungeon
{
if (!theDisplay) {
theDisplay = [[DungeonDisplay alloc]init];
[self addChild:theDisplay z:101];
[theDisplay letTheDungeon:self];
}
else {
[thePlayer placePC:thePlayer.pCLocation];
[theDisplay displayStructure];
}
theDisplay.visible = true;
aDungeonLevel.visible = NO;
}
For some reason, after addChild (a cocos method) the retain count jumps to 4 (from 1). “letTheDungeon” has no effect on retain count (as expected).
Thanks for all your answers. The problem is resolved and I again have insignificant leaking. The problem was with CCTouchDispatcher in the child class, DungeonDisplay. I changed the code for processing touches to the dungeon class and made some other minor adjustments and everyone dealloc’s are being called.
Anyway, its rock solid again. I moved over a hundred times back and forth and their was no change in allocated memory. In fact, I’m now cruising at under 70 MB, less than before.
Thanks again, especially for your words of encouragement and support.