I am using static analyser to check the memory leak of my code and I found the following part has potential leaks.
NSString *path = nil;
NSString *tutorialPath = nil;
if (CC_CONTENT_SCALE_FACTOR() == 2)
{
path = [[NSBundle mainBundle] pathForResource:@"sheetObjects-hd" ofType:@"plist"];
tutorialPath = [[NSBundle mainBundle] pathForResource:@"sheetTutorial-hd" ofType:@"plist"];
} else
{
path = [[NSBundle mainBundle] pathForResource:@"sheetObjects" ofType:@"plist"];
tutorialPath = [[NSBundle mainBundle] pathForResource:@"sheetTutorial" ofType:@"plist"];
}
_animDataDictionary = [[[NSDictionary alloc] initWithContentsOfFile:path] objectForKey:@"frames"];
_tutorialAnimDataDictionary = [[[NSDictionary alloc] initWithContentsOfFile:tutorialPath] objectForKey:@"frames"];
The problem was with these two lines:
_animDataDictionary = [[[NSDictionary alloc] initWithContentsOfFile:path] objectForKey:@"frames"];
_tutorialAnimDataDictionary = [[[NSDictionary alloc] initWithContentsOfFile:tutorialPath] objectForKey:@"frames"];
I've checked my dealloc code and I am pretty sure they are dealloced properly.
And this is how I defined the instances:
NSDictionary *_animDataDictionary;
NSDictionary *_tutorialAnimDataDictionary;
dealloc functions:
[_animDataDictionary release];
_animDataDictionary = nil;
[_tutorialAnimDataDictionary release];
_tutorialAnimDataDictionary = nil;
[super dealloc];
By checking other related questions, I have seen people complaining about the similar bugs but nobody really gets the answer and knows why it happens.
I have tons of leaks related to this code and I feel it is essential to kill it.
Thanks!