Maison > Questions et réponses > le corps du texte
大家讲道理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;
}
}
}
为工程师推荐兼职,详情点我头像