简体   繁体   中英

Ran Analyzer : Potential Memory Leak

在此处输入图片说明

Hi,

I ran the XCode analyser - and it tells me that the following both are potential memory leaks. I'm not sure why. I declared midiDevices like this

@property (assign, nonatomic) NSMutableArray* midiDevices;

Here's the code for openMidiIn

-(void)openMidiIn {
    int k, endpoints;

    CFStringRef name = NULL, cname = NULL, pname = NULL;
    CFStringEncoding defaultEncoding = CFStringGetSystemEncoding();
    MIDIPortRef mport = NULL;
    MIDIEndpointRef endpoint;
    OSStatus ret;

    /* MIDI client */
    cname = CFStringCreateWithCString(NULL, "my client", defaultEncoding);
    ret = MIDIClientCreate(cname, NULL, NULL, &mclient);
    if(!ret){
        /* MIDI output port */
        pname = CFStringCreateWithCString(NULL, "outport", defaultEncoding);
        ret = MIDIInputPortCreate(mclient, pname, MidiWidgetsManagerReadProc, self, &mport);
        if(!ret){
            /* sources, we connect to all available input sources */
            endpoints = MIDIGetNumberOfSources();
            //NSLog(@"midi srcs %d\n", endpoints);
            for(k=0; k < endpoints; k++){
                endpoint = MIDIGetSource(k);
                void *srcRefCon = endpoint;
                MIDIPortConnectSource(mport, endpoint, srcRefCon);

            }
        }
    }
    if(name) CFRelease(name);
    if(pname) CFRelease(pname);
    if(cname) CFRelease(cname);

}

Thanks for your help.


analyzer info Here's more info about the error about making a bit of changes.

在此处输入图片说明

Assuming you're using ARC, that object will actually be released and dealloc'd instantly. Why it's saying you have a memory leak is confusing, but you will have a dead reference. Use strong , not assign .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM