Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Memory is leaking in Xcode

I dont know why this is giving memory leak in xcode 4.2. Since I didn't alloc eventArraySave do I need to release it? I thought this will be added to the autorelease pool.

//Unarchive in to array
NSMutableArray *eventArraySave = [NSKeyedUnarchiver unarchiveObjectWithFile:savedfilePathName];

Do I need to release it or is there anything wrong in the above code. Also want to stress that I haven't alloced eventArraySave or inited eventArraySave. Thanks in advance :)

like image 784
user1007747 Avatar asked Jun 05 '26 14:06

user1007747


1 Answers

You should not release eventArraySave. It will be returned to you with a net retain count of 0 (after autorelease). If you're seeing leaks from this line, then that suggests that you are over-retaining it somewhere else, or possibly that you are over-retaining some object that is contained within eventArraySave (since this is where that object is allocated as well).

The leak tools do not tell you where your mistake is. They tell you where you allocated the memory that was later leaked.

like image 72
Rob Napier Avatar answered Jun 07 '26 08:06

Rob Napier