【发布时间】:2010-09-17 12:17:25
【问题描述】:
我正在开发一个应用程序,我在其中处理数据库操作。我在数据库类中写的方法如下。
-(NSMutableArray *)getData: (NSString *)dbPath{
NSMutableArray *dataArray = [[NSMutableArray alloc] init];
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK){
NSString *sqlQuery = [NSString stringWithFormat:@"SELECT empID, addText FROM Employee WHERE nameID = %@", nameID];
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, [sqlQuery UTF8String], -1, &selectstmt, NULL) == SQLITE_OK){
while (sqlite3_step(selectstmt) == SQLITE_ROW){
[dataArray addObject:[[NSMutableDictionary alloc] init]];
[[dataArray lastObject] setObject:[NSString
stringWithFormat:@"%d", sqlite3_column_int(selectstmt, 0)] forKey:@"empID"];
[[dataArray lastObject] setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,1)] forKey:@"addText"];
}
}
sqlite3_finalize(selectstmt);
}
sqlite3_close(database);
return dataArray;
}
上面的代码在模拟器上工作正常,但在设备上不行。 我也在追踪内存泄漏,我在上面的方法代码中发现了内存泄漏。但我无法解决那个内存泄漏。
现在我也发现了以下方法的内存泄漏。
- (id)initWithString:(NSString *)str 属性:(NSDictionary *)属性
{ if ((self = [super init])) { _buffer = [str mutableCopy]; _attributes = [NSMutableArray arrayWithObjects:[ZAttributeRun attributeRunWithIndex:0 attributes:attributes], nil]; } 回归自我; }
_buffer = [str mutableCopy]; 附近的泄漏。并且泄漏跟踪使我在输出中不断增加 NSCFString 字符串分配。我如何维护它?
提前致谢。
【问题讨论】:
标签: objective-c ipad