views:

45

answers:

3

In Objective-C all objects can be released from memory using release function ?

A: 

Yes,You should release all objects,if you alloc/retain/copy the objects....

carthee
A: 

Objects are not necessarily cleared from memory when you call release. Also, it might be necessary to call special functions for Core Foundation objects (such as CGColorRef). In general, you have to call one release or autorelease for every alloc, retain or copy call you make on an object.

For more details, see Apple's memory management guide.

mrueg
so that means it is not necessary that all objects can be released by released function ?
Hunt
Not sure exactly what you mean, but the release method should decrease the retain count by one for all objects (I'm not aware of any exception.) You can actually use the default release message on Core Foundation objects, too (this is called toll-free bridging).
mrueg
i think preciously you can release object that you own , not all
Hunt
+4  A: 

Not every object needs to be released. You should revise the memory management guidelines, this a comprehensive guide about memory management.

The gist of it is: if you obtained an object from a method with the word alloc, new or copy in its name, then you need to release it. You also need to balance each retain with a release or autorelease.

release only reduces an objects retain count, it does not necessarily deallocate it from memory. It is only deallocated when its retain count reaches 0.

dreamlax