我使用ARC。我发现内存不断增加。
在 .h 文件中
@property (weak, nonatomic) IBOutlet UILabel* contentALabel;
@property (weak, nonatomic) IBOutlet UILabel* contentBLabel;
在 .m 文件中
-(void)refreshContent:(NSInteger) itemID
{
sqlite3 *database;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString* databasePath = [docsPath stringByAppendingPathComponent: @"Database.sqlite"];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
NSString *sql = [NSString stringWithFormat:@"select contentA,contentB from tableA where itemID = %d ",itemID,nil];
char *sqlStatement = (char *)[sql cStringUsingEncoding:NSASCIIStringEncoding];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
NSString *contentA = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
NSString *contentB = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
contentALabel.text = contentA;
contentBLabel.text = contentB;
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
我不断地调用这个函数,我发现我的内存在“个人资料”窗口的“生活字节”列中也增加了。
但如果我评论
contentALabel.text = contentA;
contentBLabel.text = contentB;
内存不会再增加了。
' Label.text ' 有什么问题?