2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #import "NSAutoreleasePool+misc.h"
26 #if defined(LIB_FOUNDATION_LIBRARY)
28 BOOL __autoreleaseEnableRetainRemove = NO;
30 #if !LIB_FOUNDATION_BOEHM_GC
32 @implementation NSAutoreleasePool(misc)
34 // retain/remove check
36 + (void)enableRetainRemove:(BOOL)enable {
37 __autoreleaseEnableRetainRemove = enable;
40 + (NSAutoreleasePool *)findReleasingPoolForObject:(id)_obj {
41 NSAutoreleasePool *pool = nil;
43 for (pool = [self defaultPool]; pool; pool = pool->parentPool) {
44 NSAutoreleasePoolChunk *ch;
47 for (ch = pool->firstChunk; ch; ch = ch->next) {
48 for (i = 0; i < ch->used; i++) {
49 if (ch->objects[i] == _obj)
53 //if ([pool doesReleaseObject:_obj])
59 + (BOOL)retainAutoreleasedObject:(id)_obj {
60 register NSAutoreleasePool *pool = nil;
62 for (pool = [self defaultPool]; pool; pool = pool->parentPool) {
63 register NSAutoreleasePoolChunk *ch;
66 for (ch = pool->firstChunk; ch; ch = ch->next) {
67 for (i = 0; i < ch->used; i++) {
68 if (ch->objects[i] == _obj) {
74 //if ([pool doesReleaseObject:_obj])
80 - (BOOL)retainAutoreleasedObject:(id)_obj {
81 NSAutoreleasePoolChunk *ch;
84 for (ch = firstChunk; ch; ch = ch->next) {
85 for (i = 0; i < ch->used; i++) {
86 if (ch->objects[i] == _obj) {
97 @implementation NSObject(RC)
99 - (oneway void)release
101 #if BUILD_libFoundation_DLL && defined(__WIN32__)
102 extern __declspec(dllimport) BOOL __autoreleaseEnableCheck;
104 extern BOOL __autoreleaseEnableCheck;
107 // check if retainCount is Ok
108 if (__autoreleaseEnableCheck) {
109 unsigned int toCome = [NSAutoreleasePool autoreleaseCountForObject:self];
110 if (toCome+1 > [self retainCount]) {
111 NSLog(@"Release[0x%08X<%@>] release check for object %@ "
112 @"has %d references "
113 @"and %d pending calls to release in autorelease pools\n",
114 (unsigned)self, NSStringFromClass([self class]),
116 [self retainCount], toCome);
117 NSLog(@" description='%@'", [self description]);
118 abort(); // core dump for debugging
122 if (NSExtraRefCount(self) == 1)
125 NSDecrementExtraRefCountWasZero(self);
130 extern BOOL __autoreleaseEnableRetainRemove;
132 if (__autoreleaseEnableRetainRemove) {
133 if ([NSAutoreleasePool retainAutoreleasedObject:self]) {
134 NSLog(@"retained autoreleased object ..");
139 NSIncrementExtraRefCount(self);
145 #endif // !LIB_FOUNDATION_BOEHM_GC
147 #endif // defined(LIB_FOUNDATION_LIBRARY)
149 void __link_NSAutoreleasePool_misc(void) {
150 __link_NSAutoreleasePool_misc();