Hello ! every one.
I have a little query regarding the memory management.
Let's begin with an example. Assume we have a class as follows.
@interface myClass : NSObject {
NSString *xyz;
}
@end
Now, see the implementation.
@interface myClass : NSObject {
NSString *xyz;
}
@end
@implementation myClass
-(void)abc{
// xyz allocted here
}
-(void)pqr{
// retained or copied many times or may not a single time
}
-(void)mno{
// retained or copied many times or may not a single time
}
-(void)jpg{
// may be released more than one time or may be not
}
//-(void)dealloc{
// [xyz release];
// [super dealloc];
//}
//
//-(void)dealloc{
// if(xyz!=nil && [xyz retainCount]>0){ [xyz release]; xyz=nil; }
// [super dealloc];
//}
-(void)dealloc{
if(xyz!=nil){
while([xyz retainCount]>0)
[xyz release];
xyz=nil;
}
[super dealloc];
}
@end
In above code. I have three dealloc functions. Which one is preferable? If none of these, then please suggest yours. I am confused, just because - "Objective c" says, object must be released each time = each time alloc/retained.
But most of the sample code has just single statement "[xyz release];" doen't it create memory leak?
Thanks in advance for your explanation.
Sagar