How can we check that if an array has retain count=0 or not?
How can we check that if an array was in memory or not?
I have a condition where i need it
is following code is correct to release an array
if (array1)
{
[arra开发者_StackOverflowy1 release];
}
Thank you
You shouldn't be checking the retain count of objects on Obj-C. At best that number is barely useful for debugging and at worst it is grossly misleading. If you practice proper memory management techniques, you will never need to check the retain count.
If you're having trouble with memory management, post more code and we can help you track down where your problem lies. Also, if you havent read this, you should.
http://developer.apple.com/library/mac/ipad/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html%23//apple_ref/doc/uid/20000994-BAJHFBGH
Sadly, you need to know more about array1 other than its retainCount
and whether it is nil
. If you are pointing to an object that was released elsewhere, calling retainCount
can either crash your program or return complete garbage.
[Removed my comment about autorelease - it was misinformed. The above remains true still!]
If condition is correct. using that you can check whether array is in memory or not. After releasing the array you should assign nil as well. So it will remove entirely from the memory.
Cheers, Raxit
精彩评论