Точка моего представления, когда мы создаем объект, а затем устанавливаем его = nil, этот объект будет выпущен. но я попытался вставить много данных в NSMutableDictionary, а затем я установил NIL для каждого объекта. Память все еще там и не уменьшалась. См. Мой код:Объект освобождения памяти c
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableDictionary*frameAnotationLeft=[[NSMutableDictionary alloc] init];;
// Do any additional setup after loading the view, typically from a nib.
NSMutableDictionary * testDict = [[NSMutableDictionary alloc] init];
frameAnotationLeft = [[NSMutableDictionary alloc] init];
for (int j=0; j<1000; j++) {
for (int i= 0; i<5000; i++) {
NSString* __weak test = @"dule.For the most part, Automatic Reference Counting lets you completely forget about memory management. The idea is to focus on high-level functionality instead of the underlying memory management. The only thing you need to worry about are retain cycles, which was covered in the Properties module.For the most part, Automatic Reference Counting lets you completely forget about memory management. The idea is to focus on high-level functionality instead of the underlying memory management. The only thing you need to worry about are retain cycles, which was covered in the Properties module.For the most part, Automatic Reference Counting lets you completely forget about memory management. The idea is to focus on high-level functionality instead of the underlying memory management. The only thing you need to worry about are retain cycles, which was covered in the Properties module.For the most part, Automatic Reference Counting lets you completely forget about memory management. The idea is to focus on high-level functionality instead of the underlying memory management. The only thing you need to worry about are retain cycles, which was covered in the Properties module.";
NSMutableArray * arrayTest = [[NSMutableArray alloc] init];
[arrayTest addObject:test];
test = nil;
[testDict setObject:arrayTest forKey:[NSString stringWithFormat:@"%d",i]];
arrayTest = nil;
}
[frameAnotationLeft setObject:testDict forKey:[NSString stringWithFormat:@"%d",j]];
}
testDict = nil;
// Begin to release memory
for (NSString* key in frameAnotationLeft) {
NSMutableDictionary *testDict2 = (NSMutableDictionary*)[frameAnotationLeft objectForKey:key];
for (NSString* key2 in testDict2) {
NSMutableArray * arrayTest = (NSMutableArray *)[testDict2 objectForKey:key2];
NSString* test = [arrayTest objectAtIndex:0];
[arrayTest removeAllObjects];
test = nil;
arrayTest = nil;
}
[testDict2 removeAllObjects];
testDict2 = nil;
}
[frameAnotationLeft removeAllObjects];
frameAnotationLeft = nil;
}
Память при запуске - 218 мб. и это не уменьшилось. Кто-то может мне помочь и дать мне решение? Thank so muuch
Кроме того, не проверяйте управление памятью в симуляторе; он не работает так же, как и реальное устройство. Проверяйте только на устройстве, если вы хотите знать, что происходит на самом деле. – matt
Спасибо, я протестировал на реальном устройстве (как iphone, так и ipad). Я очень смущаюсь. Я также пробовал @autoreleasepool, но это не повлияло –
Но, как я уже сказал, есть проблема только в том случае, если память не может быть восстановлена. И я не думаю, что ты это знаешь. Если вы хотите узнать, сохраняются ли нежелательные объекты, используйте инструмент «Инструменты выделения». Если вы хотите узнать, есть ли _leak_, используйте инструмент «Утечки инструментов». Если нет, то не беспокойтесь и не двигайтесь дальше. – matt