Reputation: 7993
I wish best understand the difference between dealloc and release function.... example... I have my class derived from NSObject calle MyClass in my code, to use this class, I create an instance of MyClass..
// initialization
MyClass* test = [[MyClass alloc] init];
//do some stuff....
// release??
[ test release];
is right?? and the dealloc??? needs to be used in sequency or one overwrite the other??
Upvotes: 1
Views: 398
Reputation: 3899
dealloc is automatically called when retainCount is == 0. Each time you call [test release] the retainCount is decreased by one.
In your example everything is fine, since you have alloc test (retain count +1) and then release (retain count 0). Dealloc will be automatically called
Upvotes: 2
Reputation: 2192
As long as that's the end of test
's life, you're correct. Dealloc of test
will automatically happen as a function of your [ test release]
statement.
Upvotes: 1