开发者

Which method should use to release an object?

开发者 https://www.devze.com 2022-12-21 01:28 出处:网络
I found that the iphone have viewDidUnload, and dealloc. I want to release the object. Which method should I use to release the object? What\'s the different between the开发者_运维技巧m?Send release o

I found that the iphone have viewDidUnload, and dealloc. I want to release the object. Which method should I use to release the object? What's the different between the开发者_运维技巧m?


Send release or autorelease to release an object. You shouldn't send dealloc; the Obj-C runtime will do that.

If you're asking where you should release an owned object, read: "When should I release objects in -(void)viewDidUnload rather than in -dealloc?"


Do not call dealloc. Use the retain-release model for memory management, and Objective-C will take care of deallocating memory for you.

See this link for a good explanation of how retain-release works.


The difference is that viewDidUnload is used to release "spare" objects in low memory situations while dealloc is used to release all objects when the view is no longer needed.

This means that you will almost always have a dealloc method but have a viewDidUnload method only where it makes sense.

0

精彩评论

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