Uialertview and memory management

你离开我真会死。 提交于 2019-12-14 03:59:23

问题


If I alloc unit a UIAlertview and then show it. Should I release it after the show or should I autorelease it?


回答1:


This is the common way of showing an alert:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Title:" 
                                                message: @"The Message"
                                               delegate: self
                                      cancelButtonTitle: @"OK"
                                      otherButtonTitles: nil];
[alert show];
[alert release];



回答2:


Release it after the show. It will retain itself until no longer needed.




回答3:


It is good programming style to release it manually. Autorelease will also do the same thing but at it's own time. So it might release it latter also.



来源:https://stackoverflow.com/questions/4365064/uialertview-and-memory-management

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!