I have been programming on iPhone for quite sometime and have had bad experiences with memory management. I was wondering if the following way is a good way to release memory.
int count = [someObject retainCount];
for (int i = 0; i < count; i ++)
{
[someObject release];
}
This method was an act of desperation in a few situations (particularly UIWebViews) I had faced. The variable’s retainCount is reduced to zero which will release the memory being used by it. The method is a little dirty but are there any bottlenecks associated with it?
You should not rely on the
retainCountbecause there are possibility of retaining the object byiOSframeworks,Read below what Apple say about
retainCount.To understand the fundamental rules of memory management that you must abide by, read “Memory Management Rules”. To diagnose memory management problems, use a suitable tool: