gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSAutoreleasePool drain/dealloc


From: Ivan Vučica
Subject: NSAutoreleasePool drain/dealloc
Date: Tue, 6 Mar 2018 17:08:27 +0000

Hi,

I was explaining refcounting and NSAutoreleasePool to someone, and I thought referencing GNUstep might be useful to explain the correct mental model of the behavior.

But I'm confused about -drain in the non-ARC implementation:
  https://github.com/gnustep/libs-base/blob/b8185fa6c13172436c070ab3bf60b3f12bce433b/Source/NSAutoreleasePool.m#L546

Won't equating drain and dealloc mean that pools will misbehave, and that after [pool drain], the incorrect pool will get populated (and later drained)?

Am I correctly interpreting that this happens? If so, is it correct that this happens?

NSAutoreleasePool * outerPool = [NSAutoreleasePool new];
[[NSObject new] autorelease]; // object 0 added to outerPool

NSAutoreleasePool * innerPool = [NSAutoreleasePool new];
[[NSObject new] autorelease]; // object 1 added to innerPool
[innerPool drain]; // object 1 released; outerPool is the closest pool
[[NSObject new] autorelease]; // object 2 added to outerPool
[innerPool release]; // object 2 released, object 0 released; new pool created as the closest pool

[outerPool release]; // no objects released; new pool created as the closest pool

Unless I am missing something, object 0 would be released early here?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]