Reputation: 879
If i create a simple class like this
@interface table : NSObject {
NSMutableArray *array;
}
@end
and in the Init method I call: array = [[NSMUtableArray alloc] init];
and in the dealloc method I call: [array release];
but I have a memory leek because the dealloc method is never called. I must call the dealloc method by myself?
Upvotes: 2
Views: 2684
Reputation: 186984
This all looks correct. Your instance of class table
here, will have it's dealloc
method called when it is completely released. So you only have a leak if the way you use your class causes the entire instance of table
to leak.
But, of course, the same rules apply for any classes that uses your table
class.
Upvotes: 0
Reputation: 1782
When an object's retain count hits 0 it is marked by the run time for cleanup. When the run time cleans up the object and reclaims the memory, dealloc is called giving it a chance to clean any other object references to instance variables or the like. Does that help? If you want to see it called, put
NSLog(@"%s", _cmd);
or a break point at the beginning of your dealloc method and watch the debugger/console.
Upvotes: 1
Reputation: 3834
No. You should never directly call [self dealloc]
. What is it that gives you the impression that -dealloc
is never called?
EDIT: You should never need to call [table dealloc]
either. The only time you should ever send a dealloc
message is when overriding dealloc
and calling [super dealloc]
.
Upvotes: 0