//組織字典數據 - (NSMutableDictionary *)setupDicData{ NSMutableDictionary *dict = [NSMutableDictionary dictionary]; for (int i = 0; i <= 30; i++) { [dict setObject:[self setupArrayData] forKey:[NSString stringWithFormat:@"%d%@",i,@"class"]]; } return dict; } //組織數組數據 - (NSMutableArray *)setupArrayData{ NSMutableArray *marry = [NSMutableArray array]; for (int i = 0; i<=30; i++) { NSString *s = [NSString stringWithFormat:@"%@",@"data-test"]; [marry addObject:s]; } return marry; }
運行+——數組
- (void)viewDidLoad { [super viewDidLoad]; while (true) { //30.0定時執行 [NSThread sleepForTimeInterval:30.0]; NSDictionary *dict = [self setupDicData]; NSLog(@"%@",dict); //每次數據內存都得不到釋放 } }
//@autoreleasepool {}的做用是在每次循環一次,都會把內存主動釋放掉 - (void)viewDidLoad { [super viewDidLoad]; while (true) { @autoreleasepool { //30.0定時執行 [NSThread sleepForTimeInterval:30.0]; NSDictionary *dict = [self setupDicData]; NSLog(@"%@",dict); //每次數據內存都得不到釋放 } } }
- (void)usingDatadosomething{ //30.0定時執行 [NSThread sleepForTimeInterval:0.10]; NSDictionary *dict = [self setupDicData]; NSLog(@"%@",dict); //每次數據內存都得不到釋放 } - (void)viewDidLoad { [super viewDidLoad]; [NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(usingDatadosomething) userInfo:self repeats:YES]; [[NSRunLoop currentRunLoop] run]; }
內存圖以下oop