我在iOS中使用表视图时遇到了一些内存问题。
我有一个像这样的屏幕设置,所以有一个View Controller会转到另一个带有表视图的视图控制器。
每次我进入带有表视图的控制器并返回时,我的内存将继续增加大约1 MB。
因此,在一些屏幕更改中,内存使用量会变大
为什么会发生这种情况的任何想法?
由于
具有表视图的视图控制器的代码:
查看了加载方法:
questionGroups = [[NSMutableArray alloc] init];
// Do any additional setup after loading the view.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
NSString *databasePath = [path stringByAppendingPathComponent:@"databaseApp.sql"];
sqlite3 *database = NULL;
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK){
const char *sql = "SELECT * FROM question_groups";
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK){
while (sqlite3_step(statement) == SQLITE_ROW) {
NSMutableArray *questionType = [[NSMutableArray alloc] init];
NSString *groupName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
NSString *groupId = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
[questionType addObject:groupId];
[questionType addObject:groupName];
[questionGroups addObject:questionType];
questionType = nil;
}
sqlite3_finalize(statement);
statement = nil;
}
sqlite3_close(database);
}
database = NULL;
//populiranje liste
self.table.delegate = self;
self.table.dataSource = self;
单元格创建:
static NSString *CellIndentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
NSInteger row = indexPath.row;
cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@",questionGroups[row][0],questionGroups[row][3]];