2003-07-29 18:02:03 +00:00
|
|
|
#include "AutoreleasePool.h"
|
2010-12-16 11:01:49 +00:00
|
|
|
#include "Array+Private.h"
|
2003-07-29 18:02:03 +00:00
|
|
|
|
2010-12-16 11:23:52 +00:00
|
|
|
#include "Array.h"
|
|
|
|
#include "Array+Private.h"
|
2003-07-29 18:02:03 +00:00
|
|
|
|
2011-02-07 13:16:16 +00:00
|
|
|
@static Array *poolStack;
|
2003-07-29 18:02:03 +00:00
|
|
|
|
|
|
|
@implementation AutoreleasePool
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if (!(self = [super init]))
|
2011-01-14 03:07:40 +00:00
|
|
|
return nil;
|
2003-07-29 18:02:03 +00:00
|
|
|
|
2010-12-12 01:25:09 +00:00
|
|
|
if (!poolStack)
|
|
|
|
poolStack = [[Array alloc] initWithCapacity: 1];
|
2003-07-29 18:02:03 +00:00
|
|
|
|
2010-12-12 01:25:09 +00:00
|
|
|
[poolStack addObjectNoRetain: self];
|
2010-11-22 04:26:23 +00:00
|
|
|
|
2010-12-12 01:25:09 +00:00
|
|
|
array = [Array new];
|
2010-11-22 04:26:23 +00:00
|
|
|
return self;
|
2003-07-29 18:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) addObject: (id)anObject
|
|
|
|
{
|
2010-12-12 01:25:09 +00:00
|
|
|
if (!poolStack || [poolStack count])
|
2010-11-22 04:26:23 +00:00
|
|
|
[[AutoreleasePool alloc] init];
|
2010-12-12 01:25:09 +00:00
|
|
|
|
|
|
|
[[poolStack lastObject] addObject: anObject];
|
2003-07-29 18:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addObject: (id)anObject
|
|
|
|
{
|
2010-12-12 01:25:09 +00:00
|
|
|
[array addObjectNoRetain: anObject];
|
2003-07-29 18:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) retain
|
|
|
|
{
|
|
|
|
[self error: "Don't send -retain to an autorelease pool."];
|
|
|
|
}
|
|
|
|
|
2010-12-12 01:25:09 +00:00
|
|
|
- (id) autorelease
|
2003-07-29 18:02:03 +00:00
|
|
|
{
|
2010-12-12 01:25:09 +00:00
|
|
|
[self error: "Don't send -autorelease to an autorelease pool."];
|
2010-11-22 04:26:23 +00:00
|
|
|
}
|
2003-07-29 18:02:03 +00:00
|
|
|
|
2010-12-12 01:25:09 +00:00
|
|
|
- (void) dealloc
|
2010-11-22 04:26:23 +00:00
|
|
|
{
|
2010-12-12 01:25:09 +00:00
|
|
|
[array release];
|
|
|
|
[poolStack removeObjectNoRelease: self];
|
|
|
|
[super dealloc];
|
2003-07-29 18:02:03 +00:00
|
|
|
}
|
|
|
|
|
2010-12-12 01:25:09 +00:00
|
|
|
@end
|
2003-07-29 18:02:03 +00:00
|
|
|
|
2010-12-12 01:25:09 +00:00
|
|
|
void
|
|
|
|
ARP_FreeAllPools (void)
|
|
|
|
{
|
|
|
|
[poolStack removeAllObjects];
|
2003-07-29 18:02:03 +00:00
|
|
|
}
|