//组织字典数据- (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]; }
内存图如下
新闻热点
疑难解答