Check Hold Counter

I'm doing it:

UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mainback.jpg"]]; [self.view addSubview:backgroundImage]; NSLog(@" retain count1 : %d " , [backgroundImage retainCount]); [self.view sendSubviewToBack:backgroundImage]; [backgroundImage release]; NSLog(@" retain count2 : %d " , [backgroundImage retainCount]); 

I got

 retain count1 : 2 retain count2 : 1 

1) in the dealoc function, I can get a message like:

 - (void)dealloc{ NSLog(@" retain count2 : %d " , [backgroundImage retainCount]); [super dealloc]; } 

And 2) finally I got the value count 1 for backgroundimage , so is this normal or should it be 0 (zero) ?

Thanks..

+1
iphone xcode4 dealloc retaincount
source share
1 answer

According to Apple docs ,

The saveCount method does not take into account pending messages sent to the recipient.

Important: This method usually does not matter in the debug memory of a control problem . Since any number of infrastructure objects can have a saved object for storing links to it, and at the same time, abstract pools can contain any number of pending releases on the object, it is very unlikely that you can get useful information from this method . To understand the basic rules of memory management that you must follow, read "Memory Management Rules." Use the appropriate tool to diagnose memory management problems: The LLVM / Clang Static analyzer can usually find memory management problems even before running your program. Object Alloc tool in the Tools application (see the Tools User Guide). placement of objects and their destruction. Shark (see the Shark User Guide) also profile memory allocations (among many other aspects of your program).

+3
source share

All Articles