potential leak of an object allocated and stored into ...

编程知识 更新时间:2023-05-01 23:47:20

出现了标题的错误

查了一通,内存管理的问题


http://stackoverflow/questions/9286782/potential-leak-of-an-object-allocated-and-stored-into-annot


https://developer.apple/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html


这个例子很好:


You could also implement the fullName method like this:

- (NSString *)fullName {
    NSString *string = [NSString stringWithFormat:@"%@ %@",
                                 self.firstName, self.lastName];
    return string;
}

Following the basic rules, you don’t own the string returned by stringWithFormat:, so you can safely return the string from the method.

By way of contrast, the following implementation is wrong:

- (NSString *)fullName {
    NSString *string = [[NSString alloc] initWithFormat:@"%@ %@",
                                         self.firstName, self.lastName];
    return string;
}






更多推荐

potential leak of an object allocated and stored into ...

本文发布于:2023-04-24 14:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/213db761fee57f5bc12736610160cf7d.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:leak   potential   object   stored   allocated

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 100836文章数
  • 26067阅读数
  • 0评论数