Is calling [self release] allowed to control object lifetime?

前端 未结 6 2260
终归单人心
终归单人心 2020-12-07 00:40

I want to create an object in Objective C but I don\'t hold a reference to it.

Is it allowed to let the object control its own lifetime by calling [self release]?

6条回答
  •  抹茶落季
    2020-12-07 00:59

    To quote the great philosopher Alicia Silverstone, "I had an overwhelming sense of ickiness" when I read that. But I couldn't really tell you why.

    I think I would use autorelease rather than a simple release since you're still executing code in self when you call it, but other than that I can't think of any technical reasons why it wouldn't work.

提交回复
热议问题