Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -442,20 +442,26 @@ } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; id *objs = [array cArray]; size_t i, count = [array count]; BOOL stop = NO; - for (i = 0; i < count && !stop; i++) + for (i = 0; i < count && !stop; i++) { block(objs[i], i, &stop); + [pool releaseObjects]; + } + + [pool release]; } - (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block { + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFArray *ret; size_t count = [array count]; id *tmp = [self allocMemoryForNItems: count withSize: sizeof(id)]; @@ -464,33 +470,45 @@ size_t i; for (i = 0; i < count; i++) tmp[i] = block(objs[i], i); - ret = [OFArray arrayWithCArray: tmp - length: count]; + ret = [[OFArray alloc] initWithCArray: tmp + length: count]; + + @try { + [pool release]; + } @finally { + [ret autorelease]; + } } @finally { [self freeMemory: tmp]; } return ret; } - (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block { + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFArray *ret; size_t count = [array count]; id *tmp = [self allocMemoryForNItems: count withSize: sizeof(id)]; @try { id *objs = [array cArray]; size_t i, j = 0; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { if (block(objs[i], i)) tmp[j++] = objs[i]; + + [pool releaseObjects]; + } + + [pool release]; ret = [OFArray arrayWithCArray: tmp length: j]; } @finally { [self freeMemory: tmp]; Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -600,16 +600,22 @@ #ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndObjectsUsingBlock: (of_dictionary_enumeration_block_t)block { + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; size_t i; BOOL stop = NO; - for (i = 0; i < size && !stop; i++) - if (data[i] != NULL && data[i] != DELETED) + for (i = 0; i < size && !stop; i++) { + if (data[i] != NULL && data[i] != DELETED) { block(data[i]->key, data[i]->object, &stop); + [pool releaseObjects]; + } + } + + [pool release]; } - (OFDictionary*)mappedDictionaryUsingBlock: (of_dictionary_map_block_t)block { OFMutableDictionary *dict = [OFMutableDictionary dictionary]; Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -18,10 +18,11 @@ #include #import "OFMutableArray.h" #import "OFDataArray.h" +#import "OFAutoreleasePool.h" #import "OFExceptions.h" @implementation OFMutableArray - copy { @@ -224,10 +225,11 @@ } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; id *objs = [array cArray]; size_t i, count = [array count]; BOOL stop = NO; unsigned long mutations2 = mutations; @@ -235,15 +237,19 @@ if (mutations != mutations2) @throw [OFEnumerationMutationException newWithClass: isa]; block(objs[i], i, &stop); + [pool releaseObjects]; } + + [pool release]; } - (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block { + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; id *objs = [array cArray]; size_t i, count = [array count]; BOOL stop = NO; unsigned long mutations2 = mutations; @@ -259,9 +265,13 @@ selector: _cmd]; [new retain]; [objs[i] release]; objs[i] = new; + + [pool releaseObjects]; } + + [pool release]; } #endif @end Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -17,10 +17,11 @@ #include "config.h" #include #import "OFMutableDictionary.h" +#import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "macros.h" #define BUCKET struct of_dictionary_bucket #define DELETED &of_dictionary_deleted_bucket @@ -273,26 +274,32 @@ #ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndObjectsUsingBlock: (of_dictionary_enumeration_block_t)block { + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; size_t i; BOOL stop = NO; unsigned long mutations2 = mutations; for (i = 0; i < size && !stop; i++) { if (mutations != mutations2) @throw [OFEnumerationMutationException newWithClass: isa]; - if (data[i] != NULL && data[i] != DELETED) + if (data[i] != NULL && data[i] != DELETED) { block(data[i]->key, data[i]->object, &stop); + [pool releaseObjects]; + } } + + [pool release]; } - (void)replaceObjectsUsingBlock: (of_dictionary_replace_block_t)block { + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; size_t i; BOOL stop = NO; unsigned long mutations2 = mutations; for (i = 0; i < size && !stop; i++) { @@ -309,10 +316,14 @@ selector: _cmd]; [new retain]; [data[i]->object release]; data[i]->object = new; + + [pool releaseObjects]; } } + + [pool release]; } #endif @end