2003-07-29 18:02:03 +00:00
|
|
|
#include "AutoreleasePool.h"
|
2010-11-22 04:26:23 +00:00
|
|
|
//#include "Stack.h"
|
2003-07-29 18:02:03 +00:00
|
|
|
|
|
|
|
@static AutoreleasePool sharedInstance;
|
2010-11-22 04:26:23 +00:00
|
|
|
//@static Stack poolStack;
|
2003-07-29 18:02:03 +00:00
|
|
|
|
|
|
|
@interface AutoreleasePool (Private)
|
|
|
|
- (void) addItem: (id)anItem;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AutoreleasePool
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if (!(self = [super init]))
|
|
|
|
return NIL;
|
|
|
|
|
2010-11-22 04:26:23 +00:00
|
|
|
//if (!poolStack)
|
|
|
|
// poolStack = [Stack new];
|
2003-07-29 18:02:03 +00:00
|
|
|
|
|
|
|
if (!sharedInstance)
|
|
|
|
sharedInstance = self;
|
2010-11-22 04:26:23 +00:00
|
|
|
|
|
|
|
array = [[Array alloc] init];
|
|
|
|
return self;
|
2003-07-29 18:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) addObject: (id)anObject
|
|
|
|
{
|
2010-11-22 04:26:23 +00:00
|
|
|
if (!sharedInstance)
|
|
|
|
[[AutoreleasePool alloc] init];
|
|
|
|
[sharedInstance addObject: anObject];
|
2003-07-29 18:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addObject: (id)anObject
|
|
|
|
{
|
2010-11-22 04:26:23 +00:00
|
|
|
[array addItem: anObject];
|
|
|
|
[anObject release]; // the array retains the item, and releases when
|
|
|
|
// dealloced
|
2003-07-29 18:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) retain
|
|
|
|
{
|
|
|
|
[self error: "Don't send -retain to an autorelease pool."];
|
|
|
|
}
|
|
|
|
|
2010-11-22 04:26:23 +00:00
|
|
|
+ (void) release
|
2003-07-29 18:02:03 +00:00
|
|
|
{
|
2010-11-22 04:26:23 +00:00
|
|
|
[sharedInstance release];
|
|
|
|
sharedInstance = NIL;
|
|
|
|
}
|
2003-07-29 18:02:03 +00:00
|
|
|
|
2010-11-22 04:26:23 +00:00
|
|
|
- (/*oneway*/ void) release
|
|
|
|
{
|
2003-07-29 18:02:03 +00:00
|
|
|
[self dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2010-11-22 04:26:23 +00:00
|
|
|
//local id tmp;
|
2003-07-29 18:02:03 +00:00
|
|
|
|
2010-11-22 04:26:23 +00:00
|
|
|
[array release];
|
2003-07-29 18:02:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
This may be wrong.
|
|
|
|
Releasing an autorelease pool should keep popping pools off the stack
|
|
|
|
until it gets to itself.
|
|
|
|
*/
|
2010-11-22 04:26:23 +00:00
|
|
|
//do {
|
|
|
|
// tmp = [poolStack pop];
|
|
|
|
//} while (tmp != self);
|
2003-07-29 18:02:03 +00:00
|
|
|
|
2010-11-22 04:26:23 +00:00
|
|
|
sharedInstance = NIL;
|
2003-07-29 18:02:03 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
@end
|