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

前端 未结 4 1832
伪装坚强ぢ
伪装坚强ぢ 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:46

    The first one will leak.

    You must release or autorelease anything you [[ alloc] init] when you don't need it anymore.

    Refer to this guide.

提交回复
热议问题