NSMutableData instance leaks only on iPad (iOS 7.0.4)

Asked 1 years ago, Updated 1 years ago, 55 views

I am creating a program that records and plays audio using AudioUnit, but I encountered the following bugs:I tried everything I could, but it didn't improve at all, so I would like to ask you a question.

It appears that there is a memory leak in the middle of the callback function AURenderCallback configured on the recording side AURenderCallbackStruct.(Allocations in instruments is going up and down: 2.5KB/sec)

This is ↓ after a lot of research.

  • Removing the (omitted) part does not change the symptom
  • Removing the
  • AudioProcessor*rec, OSStatus line does not change the symptom
  • Allocations becomes constant immediately after you delete NSMutableData*data
  • If you change
  • NSMutableData*data to int or NSData, NSArray, the Allocation becomes constant immediately.
  • NSMutableData, NSMutableArray, and NSObject do not keep Allocation going up and down
  • This phenomenon was observed only on iPad mini (iOS 7.0.4) and did not occur on iPhone 4s (iOS 7.1.1).
OSStatus AURenderCallback (void* inRefCon,
                         AudioUnitRenderActionFlags*ioActionFlags,
                         constAudioTimeStamp* inTimeStamp,
                         UInt32 inBusNumber,
                         UInt32 inNumberFrames,
                         AudioBufferList*ioData)
{    
    AudioProcessor*rec=(__bridge AudioProcessor*) inRefCon;

    OSSStatus status=AudioUnitRender([recaudioUnit], ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, & testbufferList);


    NSMutableData*data=[NSMutableData alloc] init];
    /*
        ~ (omitted)
    */
    return noErr;
}

Please let me know the above.

objective-c iphone

2022-09-29 21:27

1 Answers

I know the AudioUnit of Mac in my own way, but the Objective-C
I am not familiar with memory management systems.

In , this source has a seemingly leaky implementation.
Since alloc is a method for securing memory,
every time it is called It secures the memory, but it doesn't seem to be open.
AURenderCallback runs quite often, so
You can imagine that memory usage will increase just by looking at the source.

In the first place,
Memory retention processing within AURENDERCallback is performed. It's not a very good strategy, so you can use NSMutableData* data in AURENDERCallback. We recommend that you modify the action so that does not alloc.

I think there are many ways to do it, but if I were you, I would be given it as an argument for AURENDERCallback
Alloc on the AudioProcessor side and implement for AURenderCallback.
I don't know what's going on with the rest of the AURENDERCallback from this source, so
I will not write a specific source, but I will not be able to process memory retention within AURENDERCallback. It is often better to write a program as a prerequisite.


2022-09-29 21:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.