大家讲道理2017-04-17 15:46:11
如果循環很多,可以手動加上釋放池:
@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;
}
}
}
推薦我兼職工程師,詳情點我頭像