2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #import "NSAutoreleasePool+misc.h"
25 #if defined(LIB_FOUNDATION_LIBRARY)
27 BOOL __autoreleaseEnableRetainRemove = NO;
29 #if !LIB_FOUNDATION_BOEHM_GC
31 @implementation NSAutoreleasePool(misc)
33 // retain/remove check
35 + (void)enableRetainRemove:(BOOL)enable {
36 __autoreleaseEnableRetainRemove = enable;
39 + (NSAutoreleasePool *)findReleasingPoolForObject:(id)_obj {
40 NSAutoreleasePool *pool = nil;
42 for (pool = [self defaultPool]; pool; pool = pool->parentPool) {
43 NSAutoreleasePoolChunk *ch;
46 for (ch = pool->firstChunk; ch; ch = ch->next) {
47 for (i = 0; i < ch->used; i++) {
48 if (ch->objects[i] == _obj)
52 //if ([pool doesReleaseObject:_obj])
58 + (BOOL)retainAutoreleasedObject:(id)_obj {
59 register NSAutoreleasePool *pool = nil;
61 for (pool = [self defaultPool]; pool; pool = pool->parentPool) {
62 register NSAutoreleasePoolChunk *ch;
65 for (ch = pool->firstChunk; ch; ch = ch->next) {
66 for (i = 0; i < ch->used; i++) {
67 if (ch->objects[i] == _obj) {
73 //if ([pool doesReleaseObject:_obj])
79 - (BOOL)retainAutoreleasedObject:(id)_obj {
80 NSAutoreleasePoolChunk *ch;
83 for (ch = firstChunk; ch; ch = ch->next) {
84 for (i = 0; i < ch->used; i++) {
85 if (ch->objects[i] == _obj) {
96 @implementation NSObject(RC)
98 - (oneway void)release
100 #if BUILD_libFoundation_DLL && defined(__WIN32__)
101 extern __declspec(dllimport) BOOL __autoreleaseEnableCheck;
103 extern BOOL __autoreleaseEnableCheck;
106 // check if retainCount is Ok
107 if (__autoreleaseEnableCheck) {
108 unsigned int toCome = [NSAutoreleasePool autoreleaseCountForObject:self];
109 if (toCome+1 > [self retainCount]) {
110 NSLog(@"Release[0x%p<%@>] release check for object %@ "
111 @"has %d references "
112 @"and %d pending calls to release in autorelease pools\n",
113 (unsigned)self, NSStringFromClass([self class]),
115 [self retainCount], toCome);
116 NSLog(@" description='%@'", [self description]);
117 abort(); // core dump for debugging
121 if (NSExtraRefCount(self) == 1)
124 NSDecrementExtraRefCountWasZero(self);
129 extern BOOL __autoreleaseEnableRetainRemove;
131 if (__autoreleaseEnableRetainRemove) {
132 if ([NSAutoreleasePool retainAutoreleasedObject:self]) {
133 NSLog(@"retained autoreleased object ..");
138 NSIncrementExtraRefCount(self);
144 #endif // !LIB_FOUNDATION_BOEHM_GC
146 #endif // defined(LIB_FOUNDATION_LIBRARY)
148 void __link_NSAutoreleasePool_misc(void) {
149 __link_NSAutoreleasePool_misc();