在调用removeAllObjects之后,NSMutableArray不能释放对象
我是一个开发ios应用的新人。
@property (copy, nonatomic) NSMutableArray* dataBufferArray;
下面的代码运行在经常调用的回调函数中。
[analyzer.dataBufferArray addObject:[NSNumber numberWithInteger:thisFrame]]; [analyzer.dataBufferArray removeAllObjects];
代码在ARC中运行。
我发现内存一直在增长! 最后IOS由于巨大的内存消耗而退出我的应用程序。
我的问题是:为什么removeAllObjects不能释放内存? 如何解决它?
发布更多代码
static int analyze(SAMPLE *inputBuffer,
unsigned long framesPerBuffer,
AudioSignalAnalyzer *analyzer) {
SAMPLE *pSample = inputBuffer;
for (long i = 0; i SAMPLE_RATE){
NSArray* unitSampleArray = [analyzer.dataBufferArray subarrayWithRange:NSMakeRange(0, SAMPLE_RATE - 1)];
[analyzer.dataBufferArray removeObjectsInRange:NSMakeRange(0, SAMPLE_RATE - 1)];
//use thread to process
NSInvocationOperation *operation = [[NSInvocationOperation alloc]initWithTarget:analyzer
selector:@selector(decodeSound:)
object:unitSampleArray];
[analyzer.queue addOperation: operation];
}
// for protect
if (analyzer.dataBufferArray.count > SAMPLE_RATE * 12){
NSLog(@"sample in data buffer so big, need clear");
[analyzer.dataBufferArray removeAllObjects];
}
return 0;
}
正如你所看到的,分析函数是AudioQueueNewInput的回调函数。 我用NSMutableArray添加对象NSNumber,并且我总是'removeObjectsInRange:'它们。 我用仪器检查记忆,它一直在增长!
您正在使用基于ARC的项目,不需要释放内存,它会自动管理。 你的问题是其他地方,请张贴更多的代码。
链接地址: http://www.djcxy.com/p/45763.html上一篇: NSMutableArray can not release objects after invoke removeAllObjects
下一篇: C code from Swift
