Instruments 说这个方法存在内存泄漏,但我不知道在哪里
根据仪器,
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;}
有人可以指出吗? 谢谢
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 this 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在第一个代码示例中,您没有释放
dataForCachedImage
。您可以将其更改为或
In the first sample of code you aren't releasing
dataForCachedImage
. You can either change it toor
好的..解决了!...问题是catThumb 没有在Category 类中发布。就是这样!,不需要其他修改......无论如何,谢谢大家!
ok.. resolved it!... the problem was that the catThumb was not released in Category class. thats it!, no other modification required... anyways, thx everybody!