From e3689458b83578dbbc4377f32e5ef10bfdc042dc Mon Sep 17 00:00:00 2001 From: Andrew McCallum Date: Fri, 4 Aug 1995 20:51:19 +0000 Subject: [PATCH] ([NSAutoreleasePool -addObject:]): Remove double_release checking. Increment released_count after setting released array. ([NSAutoreleasePool -dealloc]): Catch release errors. ([NSAutoreleasePool -enableDoubleReleaseCheck:]): Removed method. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@528 72102866-910b-0410-8b05-ffd578937521 --- Source/NSAutoreleasePool.m | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/Source/NSAutoreleasePool.m b/Source/NSAutoreleasePool.m index eca2e3928..31cc78705 100644 --- a/Source/NSAutoreleasePool.m +++ b/Source/NSAutoreleasePool.m @@ -44,10 +44,6 @@ static NSAutoreleasePool *current_pool = nil; `release' message. Memory use grows, and grows, and... */ static BOOL autorelease_enabled = YES; -/* When this is `YES', every call to addObject, checks to make sure - isn't being set up to release itself too many times. */ -static BOOL double_release_check_enabled = NO; - /* When the released_count gets over this value, we call error:. In the future, I may change this to raise an exception or call a function instead. */ @@ -109,24 +105,16 @@ static unsigned pool_count_warning_threshhold = UINT_MAX; if (!autorelease_enabled) return; - if (double_release_check_enabled) - { - unsigned release_count = [[self class] autoreleaseCountForObject:anObj]; - unsigned retain_count = [anObj retainCount]; - if (release_count > retain_count + 1) - [self error:"Autorelease would release object too many times."]; - } - if (released_count >= pool_count_warning_threshhold) [self error:"AutoreleasePool count threshhold exceeded."]; - released_count++; if (released_count == released_size) { released_size *= 2; OBJC_REALLOC(released, id, released_size); } released[released_count] = anObj; + released_count++; } - init @@ -154,13 +142,24 @@ static unsigned pool_count_warning_threshhold = UINT_MAX; { int i; + /* Make debugging easier by checking to see if we already dealloced the + object before trying to release it. Also, take the object out of the + released list just before releasing it, so if we are doing + "double_release_check"ing, then autoreleaseCountForObject: won't find the + object we are currently releasing. */ + for (i = 0; i < released_count; i++) + { + id anObject = released[i]; + if (anObject->isa == (void*) 0xdeadface) + [self error:"Autoreleasing deallocated object. Debug after setting [NSObject enableDoubleReleaseCheck:YES] to check for release errors."]; + released[i]=0; + [anObject release]; + } + OBJC_FREE(released); if (parent) current_pool = parent; else current_pool = [[NSAutoreleasePool alloc] init]; - for (i = 0; i < released_count; i++) - [released[i] release]; - OBJC_FREE(released); NSDeallocateObject(self); } @@ -175,11 +174,6 @@ static unsigned pool_count_warning_threshhold = UINT_MAX; autorelease_enabled = enable; } -+ (void) enableDoubleReleaseCheck: (BOOL)enable -{ - double_release_check_enabled = enable; -} - + (void) setPoolCountThreshhold: (unsigned)c { pool_count_warning_threshhold = c;