根据仪器,这些线路存在内存泄漏
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];
在以下代码中。
我还对代码进行了静态分析..在此文件中没有显示任何问题。
-(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;}
有人可以指出吗? 感谢
答案 0 :(得分:1)
在第一个代码示例中,您没有发布dataForCachedImage
。您可以将其更改为
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.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];
答案 1 :(得分:0)
确定..解决了!...问题是catThumb没有在Category类中发布。多数民众赞成!,不需要其他修改......无论如何,大家好!