Friday 15 June 2012

objective c - In ARC, why is self in init methods a consumed parameter? -


I understand ARC, and I am reading this:

It says that an consumption parameter is maintained before the call, and at the end of the function (inside the function body) is released. It says that init ... methods have been effectively marked with ns_consumes_self . I do not see this point.

  Foo * Foo = [[Foo Alok] initWith whatever: x];   

then returns an object with the number of maintaining one of alloc 1, right? Now then is placed before going into init , and then is released at the end of init , so we come back to 1 Go. Why did it design like this? When I feel like the typical init , I get more confused.

  self = [super-init]; If (self) {...} return itself;    

Then the assignment gives an returns with an object 1 No? Now it has been preserved again before moving in init, and then it has been released at the end of the init, so we are back at 1. Why is this designed like this? Perhaps the starters can return an indication to a different object, which initially indicates self a -init method can say: I do not like this object, I think I'll give the option of a different one and it's absolutely fine. Prior to ARC, such a facilitator will clearly release self (even if it has never been placed) and then assign it to some other pointers. Possibly, the ns_consumes_self directive will take care of issuing the object that was passed in the beginning, even if itself is pointing to another object within the law .

When I think that looks like normal init, I get more confused.

It is a good bet that behavior is to cover cases that are not like a specific -init method Modifying self is not exactly specific, it is simply acceptable.

No comments:

Post a Comment