使用stringWithCString进行内存泄漏

时间:2011-12-07 07:33:23

标签: iphone memory-management

嗨,所有我得到的内存泄漏与以下代码行。如何解决....

const char *value = (const char *)sqlite3_column_text(statement, i);
[result setObject:[NSString stringWithCString:value encoding:NSUTF8StringEncoding] forKey:columnName];

const char *value = (const char*)sqlite3_column_text(statement, i);
NSString *str_Value = [[NSString alloc] initWithFormat:@"%@",[NSString stringWithUTF8String:value]] ;
[result setObject:str_Value forKey:columnName];
[str_Value release];

如何消除这种泄漏。请帮忙......

1 个答案:

答案 0 :(得分:0)

您需要对其进行无效检查;

if (value != null)
{
   NSString *str_Value = [[NSString alloc] initWithFormat:@"%@",[NSString 
   stringWithUTF8String:value]] ;
  [result setObject:str_Value forKey:columnName];
}