84669 Lernen von Personen
152542 Lernen von Personen
20005 Lernen von Personen
5487 Lernen von Personen
7821 Lernen von Personen
359900 Lernen von Personen
3350 Lernen von Personen
180660 Lernen von Personen
48569 Lernen von Personen
18603 Lernen von Personen
40936 Lernen von Personen
1549 Lernen von Personen
1183 Lernen von Personen
32909 Lernen von Personen
ringa_lee
NSThread线程中不要使用NSData的subdataWithRange方法
转来的,你可以看看
代码没给全吧,也没看出来对data做了啥操作啊。另外,在主线程调用sleepForTimeInterval会卡住UI线程的。
楼主确定这这些代码引起的内存增长吗?如果确定,可以在这个函数入口加个断点,然后一步一步的调试,看看走完哪一行代码后内存有的增长
如果循环很多,可以手动加上释放池:
@autoreleasepool { your code }
例如你的代码改为:
- (void)viewDidLoad { [super viewDidLoad]; staitc int EVERBUFFERLEN = 2000; NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"wakeup.pcm" ofType:nil]]; NSMutableData *mData = [NSMutableData dataWithData:data]; int readLength = 0; while (readLength < mData.length) { if (mData.length - readLength > EVERBUFFERLEN) { @autoreleasepool { NSData *data = [mData subdataWithRange:NSMakeRange(readLength, EVERBUFFERLEN)]; readLength += EVERBUFFERLEN; [NSThread sleepForTimeInterval:0.01]; data = nil; } } }
为工程师推荐兼职,详情点我头像
转来的,你可以看看
代码没给全吧,也没看出来对data做了啥操作啊。另外,在主线程调用sleepForTimeInterval会卡住UI线程的。
楼主确定这这些代码引起的内存增长吗?如果确定,可以在这个函数入口加个断点,然后一步一步的调试,看看走完哪一行代码后内存有的增长
如果循环很多,可以手动加上释放池:
例如你的代码改为: