0
點我的看法,當我們創建對象,然後將其設置=零,這個對象將是釋放。但我試圖插入大量的數據到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 MB。並沒有減少。有人可以幫助我,給我解決方案?謝謝如果你正在使用ARC,局部變量設置爲nil
沒有必要如此muuch
另外,不要在模擬器中測試內存管理;它不像真實設備那樣工作。如果您想知道實際發生的情況,只能在設備上進行測試。 – matt
謝謝,我在真實設備上測試過(iphone和ipad)..我很迷惑它。我也試過了@autoreleasepool,但它不起作用 –
但是,正如我所說的,如果內存不能被回收,那隻會有問題。我不認爲你知道這一點。如果您想知道不需要的對象是否持續存在,請使用「儀器分配」工具。如果您想知道是否有_leak_,請使用「儀器泄漏」工具。如果沒有,那麼不要擔心,繼續前進。 – matt