Objective-C Memory Question

后端 未结 6 790
感动是毒
感动是毒 2021-01-23 07:45

Is it a leak if I have a view controller and allocate the view like this:

self.view = [[UIView alloc] initWithFrame:frame];

Do I need to do som

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-23 08:18

    There is a very simple rule for Objective-C memory management. If you've sent retain message, you've to send release also. I do not know exceptions with this rule is SDK itself.

    Here we've alloc, that sends retain itself (always), so you have to release object somewhere. You can do it in dealloc or right here, after assigning it to self.view.

提交回复
热议问题