Skip to content

Commit

Permalink
memory leak, delgate retain cycles fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Isaac Tewolde <[email protected]>
Isaac Tewolde committed Jul 4, 2011
1 parent 061034a commit 19d2975
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions src/TSDB.m
Original file line number Diff line number Diff line change
@@ -176,7 +176,7 @@ -(id)initWithDBNamed:(NSString *)dbName inDirectoryAtPathOrNil:(NSString*)path d
return nil;
}
//NSLog(@"%@", theDBPath);
_delegate = [theDelegate retain];
_delegate = theDelegate;
if (isNew) {
[self reindexDB:nil];
}
@@ -188,19 +188,24 @@ - (void)setDelegate:(id<TSDBDefinitionsDelegate>)aDelegate
_delegate = aDelegate;

}
-(id)delegate{
return _delegate;
}
- (void) dealloc
{
dispatch_sync(dbQueue, ^{
_delegate = nil;
//tcmapdel(reuseableTCMap);
[orderBy release];
//dispatch_release(dbQueue);
[dbDir release];
[dbNamePrefix release];
[rootDBDir release];
[dbFilePath release];

[filterChain release];
[_delegate release];
});

[super dealloc];
}
-(void)syncDB{
@@ -800,25 +805,25 @@ -(void)adjustQuery:(TDBQRY *)qry withLimit:(NSUInteger)resultLimit andOffset:(NS
tctdbqrysetlimit(qry, (int)resultLimit, (int)resultOffset);
}
-(NSArray *)fetchRows:(TDBQRY *)qry{
NSMutableArray *rows = [NSMutableArray arrayWithCapacity:1];
NSMutableArray *rows = [[NSMutableArray alloc] initWithCapacity:1];
__block TCLIST *res;
dispatch_sync(dbQueue, ^{
res = tctdbqrysearch(qry);
});
const char *rbuf;
int rsiz, i;
//NSLog(@"########################num res: %d", tclistnum(res));
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for(i = 0; i < tclistnum(res); i++){
rbuf = tclistval(res, i, &rsiz);
NSString *key = [NSString stringWithUTF8String:rbuf];
//NSLog(@"k: %@", key);
[rows addObject:[self dbGet:key]];
}
[pool drain];
//[pool drain];
tclistdel(res);
[filterChain removeAllFilters];
return rows;
return [rows autorelease];
}
-(void)fetchRows:(TDBQRY *)qry andProcessWithBlock:(BOOL(^)(id))processingBlock{
__block TCLIST *res;
@@ -907,9 +912,9 @@ -(id)dbGet:(NSString *)rowID{
tcmapdel(cols);
}
if([_delegate respondsToSelector:@selector(TSModelObjectForData:andRowType:)]){
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
id rowModel = [[_delegate TSModelObjectForData:rowData andRowType:[rowData objectForKey:[self makeRowTypeKey]]] retain];
[pool drain];
//[pool drain];
return [rowModel autorelease];
}
return rowData;
2 changes: 1 addition & 1 deletion src/TSDBQuery.m
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ +(TSDBQuery *)TSDBQueryWithFilters:(TSRowFilterChain *)theFilters forDB:(TSDB *)
-(id)initWithDB:(TSDB *)theDB andFilters:(TSRowFilterChain *)theFilters{
self = [super init];
if (self) {
filterChain = [[theFilters copy] retain];
filterChain = [theFilters copy];
db = [theDB retain];
}
return self;

0 comments on commit 19d2975

Please sign in to comment.