Object allocate and init in Objective C

后端 未结 6 2134
日久生厌
日久生厌 2020-12-07 08:24

What is the difference between the following 2 ways to allocate and init an object?

AController *tempAController = [[AController alloc] init];
self.aControll         


        
6条回答
  •  Happy的楠姐
    2020-12-07 09:17

    Note also that your desire to cut the code down to one line is why many people use Autorelease:

    self.aController = [[[AController alloc] init] autorelease];
    

    Though in theory on the iPhone autorelease is somehow more expensive (never heard a clear explanation why) and thus you may want to explicitly release right after you assign the object elsewhere.

提交回复
热议问题