When are released objects finally destroyed?

When you release an object in Objective-C (assuming its release count is 1), its release count is reduced to 0 and the dealloc method is called. Is the object destroyed immediately after [super dealloc], or is it added to the pool and destroyed when the pool merges?

I would suggest that released objects are destroyed at the end of dealloc (when [super dealloc] is called). I know that autorelease variables are added to the pool, they just want to be sure what happens to the normal released objects.

cheers -gary -

+3
source share
2 answers

-, Objective-C . Foundation ( Cocoa Mac OS X Cocoa Touch iPhone OS). Foundation NSObject rootclass, alloc, retain, release autorelease class_createInstance() object_dispose() Objective-C .

Objective-C , NSObject no-ops . iPhone OS Mac OS X , Cocoa.

alloc NSObject NSProxy Foundation. class_createInstance(), .

"", dealloc NSObject. , object_dispose(), , NSObject NSProxy Foundation.

- , , , . , autorelease ;

-(id)autorelease; {
  [NSAutoreleasePool addObject:self];  // retain count +1
  [self release];                      // retain count -1
  return self;
}

autorelease , . , , release , , , , .

+8

, , .

, "", , , , . ( , ), . , , , , , , .

+5

Source: https://habr.com/ru/post/1717627/


All Articles