I am making an iPhone game. I want to release all objects that have been allocated or retained. In the dealloc
function I am releasing all such objects, but then I realized that sometimes I end up releasing objects when they have not been allocated yet. So I figured I need to check if its retainCount
is greater than zero or not before I release it.
My question is:
Do I just check if the retainCount
is greater than zero and then release it?
if([bg retainCount]!=0)
{
[bg release];
}
or
Should I release it as many times as its retainCount
while([bg retainCount]!=0)
{
[bg release];
}
Thanks for your help!
retainCount
of any object is none of your business. It is there as a debugging aid, but nothing more. Production code should never ever depend on it. – IleumretainCount
can never return 0 because the object has already been deallocated by the time that happens..... – Eldin