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