• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
fixing audiounit CoreFoundation memory leaks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fixing audiounit CoreFoundation memory leaks


  • Subject: fixing audiounit CoreFoundation memory leaks
  • From: Oli Larkin <email@hidden>
  • Date: Mon, 10 Oct 2011 17:50:59 +0100

I've been using the leaks tool to test the audio unit version of my  plugin which is built using the IPlug Framework. I've been following the instructions here:

http://developer.apple.com/library/mac/#technotes/tn2204/_index.html

The leaks are tiny, but I want to get rid of them! It appears that certain CFStrings are not getting released in IPlug's AU code, particularly when it comes to preset names. I am trying to find out how to release them properly but so far no joy. From everything I've read it seems that the host should release them - but i've tried releasing them myself in various places, and mostly it just crashed auval. If anyone has any idea what's wrong with the methods below it would be great to know. I had a look at the DFX au utilities which include AUPreset CF datatypes and actually I made some progress and got rid of the preset leaks (by using the DFX CFAUPreset), but the leaks for the other items remained… i'd prefer to work out the problem and fix it without including the DFX code.

dfx au utilities: http://destroyfx.smartelectronix.com/dfx-au-utilities.html#factory_presets_cfarray_callbacks

thanks 

oli larkin


info…


the leaks look like this… one for each preset name

Leak: 0x6aa65bb0  size=32  zone: DefaultMallocZone_0x117000 instance of '__NSCFString', type ObjC, implemented in CoreFoundation
0xacd21ca0 0x0100078c 0x616c470d 0x20797373 .........Glassy 
0x65637341 0x0000746e 0x00000000 0x00000000 Ascent..........
Call stack: [thread 0xac9282c0]: | 0xf50e1 | 0xf638b | 0xf600c | 0x1033d3 | 0x1009ae | _AT_AudioUnitGetProperty | CallComponentDispatch | CallComponent | IPlugAU::IPlugAUEntry(ComponentParameters*, void*) | IPlugAU::GetProperty(unsigned long, unsigned long, unsigned long, unsigned long*, unsigned char*, void*) | CFStringCreateWithCString | __CFStringCreateImmutableFunnel3 | _CFRuntimeCreateInstance | CFAllocatorAllocate | __CFAllocatorSystemAllocate | malloc_zone_malloc 

and for  each enumerated list parameter item

Leak: 0x6aa73320  size=16  zone: DefaultMallocZone_0x117000 instance of '__NSCFString', type ObjC, implemented in CoreFoundation
0xacd21ca0 0x0100078c 0x6e6f6906 0x006e6169 .........ionian.
Call stack: [thread 0xac9282c0]: | 0xf50e1 | 0xf638b | 0xf600c | 0x103654 | 0xfeb15 | 0xfe90b | 0xfe0b8 | _AT_AudioUnitGetProperty | CallComponentDispatch | CallComponent | IPlugAU::IPlugAUEntry(ComponentParameters*, void*) | IPlugAU::GetProperty(unsigned long, unsigned long, unsigned long, unsigned long*, unsigned char*, void*) | CFStringCreateWithCString | __CFStringCreateImmutableFunnel3 | _CFRuntimeCreateInstance | CFAllocatorAllocate | __CFAllocatorSystemAllocate | malloc_zone_malloc 


guilty methods:

see

https://github.com/audio-plugins/wdl-ce/blob/candidate/WDL/IPlug/IPlugAU.cpp

inline CFStringRef MakeCFString(const char* cStr)
{
  return CFStringCreateWithCString(0, cStr, kCFStringEncodingUTF8); 
}

in IPlugAU .cpp IPlugAU::GetProperty()

    case kAudioUnitProperty_FactoryPresets: {            // 24,   // listenable
      *pDataSize = sizeof(CFArrayRef);
      if (pData) {
        int i, n = NPresets();
        CFMutableArrayRef presetArray = CFArrayCreateMutable(0, n, 0);
        for (i = 0; i < n; ++i) {
          AUPreset* pAUPreset = new AUPreset;
          pAUPreset->presetNumber = i;
          pAUPreset->presetName = MakeCFString(GetPresetName(i)); // this needs to get released somewhere?
          CFArrayAppendValue(presetArray, pAUPreset);
        }
        *((CFMutableArrayRef*) pData) = presetArray;
      }
      return noErr;
    }

also 

 case kAudioUnitProperty_ParameterInfo: {             // 4,  listenable
      ASSERT_SCOPE(kAudioUnitScope_Global);
      *pDataSize = sizeof(AudioUnitParameterInfo);
      if (pData) {
        AudioUnitParameterInfo* pInfo = (AudioUnitParameterInfo*) pData;
        memset(pInfo, 0, sizeof(AudioUnitParameterInfo));
        pInfo->flags = kAudioUnitParameterFlag_CFNameRelease |
          kAudioUnitParameterFlag_HasCFNameString |
          kAudioUnitParameterFlag_IsReadable |
        kAudioUnitParameterFlag_IsWritable;
        IParam* pParam = GetParam(element);
        const char* paramName = pParam->GetNameForHost();
        pInfo->cfNameString = MakeCFString(pParam->GetNameForHost());
        strcpy(pInfo->name, paramName);   // Max 52.

        

        switch (pParam->Type()) {
          case IParam::kTypeBool:
            pInfo->unit = kAudioUnitParameterUnit_Boolean;
            break;
          case IParam::kTypeEnum:
            //fall through
          case IParam::kTypeInt: 
            pInfo->unit = kAudioUnitParameterUnit_Indexed;
            break;
          default: {
            const char* label = pParam->GetLabelForHost();
            if (CSTR_NOT_EMPTY(label)) {
              pInfo->unit = kAudioUnitParameterUnit_CustomUnit;
              pInfo->unitName = MakeCFString(label);
            }
            else {
              pInfo->unit = kAudioUnitParameterUnit_Generic;
            }
          }
        }
        double vMin, vMax;
        pParam->GetBounds(&vMin, &vMax);
        pInfo->minValue = vMin;
        pInfo->maxValue = vMax;
        pInfo->defaultValue = pParam->Value();
      }
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: USB Audio streaming start
  • Next by Date: MIDIPacketListAdd questions
  • Previous by thread: Re: USB Audio streaming start
  • Next by thread: MIDIPacketListAdd questions
  • Index(es):
    • Date
    • Thread