views:

30

answers:

2

Hello

I am running my application through xcode's static analyzer and it pointed out that I had a potential leak in a file:

MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

So after the code I do [delegate release]. This results in an EXC BAD ACCESS when the view controller I am doing this in pushes a new view controller onto the navigation stack. If I comment this out, it's fine.

I have run through the debugger and it doesn't actually crash when the delegate reference is released, but just when the next controller is pushed.

It isnt the code which runs between the declaration and the release as I tried commenting it out to see what happens.

+2  A: 

In your code you just get a reference to the application delegate object and do not retain it anywhere - so you should not release it.

So either static analyzer gives false positive here or there's some other error in the code around. But, again, considering just this line you should not release delegate.

Vladimir
+2  A: 

Calling the delegate Method does not retain the object. So you shouldn't be in charge of releasing it. Are you sure that the static analyzer is referencing this particular line of code? UIApplication itself does not retain but assign the delegate.

tob
Yup, it was the line below. That will teach me not to wear my glasses, cheers!
qui