NSMutableArray can not release objects after invoke removeAllObjects

I'm a new guy for developing ios app.

@property (copy, nonatomic) NSMutableArray* dataBufferArray;

Following code run in a callback function.which invoked frequently.

[analyzer.dataBufferArray addObject:[NSNumber numberWithInteger:thisFrame]];
[analyzer.dataBufferArray removeAllObjects];

Code run in ARC.
I found the memory always growing! Finally IOS exit my application cause by huge memory consume.

My question is: why removeAllObjects can not release the memory? How to resolve it?

post more code

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;
}

As you can see, analyze function is callback by AudioQueueNewInput. I used NSMutableArray add object NSNumber, and I always 'removeObjectsInRange:' them. I use instruments to check the memory, it always growing!


You are using ARC based project there is no need to release memory, it will automatically managed. Your problem is somewhere else please post some more code.

链接地址: http://www.djcxy.com/p/45764.html

上一篇: GCC是什么?

下一篇: 在调用removeAllObjects之后,NSMutableArray不能释放对象