开发者

iphone release dealloc

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 rig开发者_如何转开发ht?? and the dealloc??? needs to be used in sequency or one overwrite the other??


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜