Do app delegates need to be released?

Still new to the memory management in iPhone apps, I have a newbee question. Let say I have some method that use attributes of the AppDelegate. At the beginning of those methods, I get the delegate like:

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

Do I need to perform some kind of release at the end of the method (I was thinking of adding [delegate release] at the end of each methods like this one).

Generally speaking, do we have to release, at the end of the method, each object variables (NSString, NSData, ...) that were created within this method ?

Thanks a lot, Luc


Simple rule:

If when you got a reference to an object (appDelegate in this case) you didn't call alloc on the object then you don't need release. If you did call alloc in that line of code you provided then you would want to call [delegate release];

No. This is just a reference to your delegate which is most likely used by other parts of your program.

Need Your Help

Select items that are the top N results for a related table

sql subquery limit greatest-n-per-group

Say I have a game where a question is asked, people post responses which are scored, and the top 10 responses win. I have a SQL database that stores all of this information, so I might have tables ...

Fastest way to extract individual pixel data?

c++ image-processing opencv computer-vision

I have to get information about the scalar value of a lot of pixels on a gray-scale image using OpenCV. It will be traversing hundreds of thousands of pixels so I need the fastest possible method.