object release without pool-just leaking?? is this memory leak??? if yes how can i avoid this???
is this memory leak???
Yes.
if yes how can i avoid this???
You need an NSAutoreleasePool
. For example,
int main () {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
... your main code ...
[pool drain];
return 0;
}
The object isn't being released, it's being autoreleased. Autorelease is like deferred cleanup, it means "I'm done with this, feel free to get rid of it later". Sometimes another part of the code, like a function that yours was called from, will pick up the object (retain it) before the autorelease occurs.
Autoreleasing is managed by a class called NSAutoreleasePool
. The class maintains a stack of pools, and when an object is autoreleased, it is added to the topmost pool on the stack. Draining a pool causes it to release all of the objects that have been added to it - and if any have been released enough, they will be deallocated.
There are two approaches you can take to remove this message. One, which works on both the Mac and iPhone, is the one suggested by KennyTM - add an autorelease pool around you code that uses autoreleased objects. You need one for each thread where you autorelease Cocoa objects, more is possible but usually one is sufficient. The other alternative, though only if you're targeting Mac OS, is to enable garbage collection. That won't solve all of your problems but does mean that unreferenced objects are automatically removed.
If you're not familiar with retain counts and autorelease pools, you may have other memory management problems in your code. I recommend you use the static analyser on your project (choose "Build & Analyze" from Xcode's build menu) and address any issues it raises.