Discussion in 'iOS Development' started by Chicken, Jan 20, 2009.
my app works fine with these errors just wondering if there is a way to solve it
You have something similar to this in your implementation file
NSObject *someObject = [[[NSObject alloc] initWithBlah] autorelease];
someObject = [[[NSObject alloc] initWithBlah] autorelease];
Ah thanks alot skylar your great
Thank you Skylar, helped me too Please Register or Log in to view images.
Please Register or Log in to view images
I love the 'initWithBlah' Please Register or Log in to view images
And I hope you guys (Skylar does it for sure... Please Register or Log in to view images) know about Memory Management, the autorelease is fine, but not always the best choice.
(The code Skylar provided is ok but you should remember that releasing stuff at the right time is very important, especially on a portable platform. Just thought someone should mention this.)
That's a great point. If I were actually writing what I posted here into a real app, I would not use autorelease.
To tell the truth, I don't like to use autorelease all that much. Whenever possible, I use convenience constructors (which will autorelease themselves when they go out of scope), or I manually release the objects I create.
Example: [[UIImage imageNamedPlease Register or Log in to view images"image.png"] autorelease]; will give you an error, most likely a double free error. This is because the object gets released automatically as a part of its nature, and the app tries to release it.
Example: NSString aString = [NSString stringWithFormatPlease Register or Log in to view images"Variable\t%d", variable]; /*more lines of code*/[aString release]; will also cause you an error. Again, most likely a double free error.
Anyone reading this, what I posted incorrectly in my last post was autoreleasing an object that was assumed to be an ivar. Not that there's anything wrong with this, but you probably should have just made the variable local instead.
EDIY: If you guys are having issues with memory management, go ahead and set NSZombieEnabeled. It will keep objects alive in memory when released, and log out a message when they are freed or accessed again. This is a very important tool if you are having memory issues. Just, make sure to turn it off before you release your app.
I don't like using auto release IMO its easier to just release it when you need to like skylar said you can get quite a few errors. I've has errors like the ones skylar mentioned in previous apps.
Separate names with a comma.