According to instrument there is memory leak at these lines
cat.catName = (catName)?[NSString stringWithUTF8String:catName]:@"";
NSData *dataForCachedImage = [[NSData alloc] initWithBytes:sqlite3_column_blob(statement, 2) length: sqlite3_column_bytes(statement, 2)];
cat.catThumb = [UIImage imageWithData:dataForCachedImage];
[dataForCachedImage release];
in the following code.
I have also statically analyzed the code.. shows no issue in t开发者_JAVA技巧his file.
-(NSMutableArray *)getAllItems{
NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];
const char *sql = "SELECT * FROM category ORDER by sort";
sqlite3_stmt *statement;
int sqlresult = sqlite3_prepare(database, sql, -1, &statement, nil);
if (sqlresult == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
Category *cat = [[Category alloc] init];
char *catName = (char *)sqlite3_column_text(statement, 1);
cat.catID = sqlite3_column_int(statement, 0);
cat.catName = (catName)?[NSString stringWithUTF8String:catName]:@"";
NSData *dataForCachedImage = [[NSData alloc] initWithBytes:sqlite3_column_blob(statement, 2) length: sqlite3_column_bytes(statement, 2)];
cat.catThumb = [UIImage imageWithData:dataForCachedImage];
[dataForCachedImage release];
cat.catLock = sqlite3_column_int(statement, 3);
cat.sort = sqlite3_column_int(statement, 4);
cat.total = [self totalSMS:cat.catID];
[items addObject:cat];
[cat release];
}
sqlite3_finalize(statement);
}
else
{
NSLog(@"problem with the database");
NSLog(@"%d",sqlresult);
}
return items;}
can someone point out? Thanks
In the first sample of code you aren't releasing dataForCachedImage
. You can either change it to
cat.catName = (catName)?[NSString stringWithUTF8String:catName]:@"";
NSData *dataForCachedImage = [[NSData alloc] initWithBytes:sqlite3_column_blob(statement, 2) length: sqlite3_column_bytes(statement, 2)];
cat.catThumb = [UIImage imageWithData:dataForCachedImage];
[dataForCachedImage release];
or
cat.catName = (catName)?[NSString stringWithUTF8String:catName]:@"";
NSData *dataForCachedImage = [[[NSData alloc] initWithBytes:sqlite3_column_blob(statement, 2) length: sqlite3_column_bytes(statement, 2)] autorelease];
cat.catThumb = [UIImage imageWithData:dataForCachedImage];
ok.. resolved it!... the problem was that the catThumb was not released in Category class. thats it!, no other modification required... anyways, thx everybody!
精彩评论