views:

76

answers:

1

I have an app where it seems to me that memory is not being release but I am not sure how to analyze this problem.

'Analyze' in xcode shows no problems and 'Instruments' does not show any memory leaks.

As far as I have seen, it is not recommended to look at the retain counts.

How can I find the problematic objects? I have added printouts to the object's 'dealloc' method and do not see that this is being called.

Update

I am now getting that

objc[69139]: FREED(id): message retainCount sent to freed object=0x5422420

Is there an easy way to find out which object this is? 'Analyze' does not report any invalid releases.

A: 

I suggest searching through your code and finding every init/alloc statement. Then, verify for each object that it is getting released properly. If you have one problem, you likely have more. It may seem like a high cost initially, but it will likely pay off in fixed bugs.

A big thing to watch out for is references coming from nibs which you are also setting. It is very easy to have those not released. I find the easiest way to make sure there are no memory errors there is to declare them something like:

@property (nonatomic, retain) IBOutlet UILabel *message;

Then make sure dealloc is something like:

- (void)dealloc {
    self.message = 0;
    [super dealloc];
}

I did both of these a while back and all my memory errors cleared up.

Nathan S.
Thanks - started the manual scan... I actually don't have any NIBs so I guess I can cross that out...
LK
`self.message = 0` should be `[message release]`. Also, use `nil` for clearing pointers.
Shaggy Frog
Actually, it works as is. Assigning 0/nil will cause the old value to be released.
Nathan S.
Yes, but it's not a common pattern, and looks strange compared to other code.
Shaggy Frog