Does “self.propery = [[SomeClass alloc] init];” leak memory?

前端 未结 4 1836
伪装坚强ぢ
伪装坚强ぢ 2021-01-26 18:07

Is it safe in Objective-C to write

self.propery = [[SomeClass alloc] init];

instead of

SomeClass *tmp = [[SomeClass alloc] init         


        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-26 18:42

    The first example leaks unless you provide a custom property setter. You can use:

    self.propery = [[[SomeClass alloc] init] autorelease];
    

    Instead.

提交回复
热议问题