Resolved Memory never released in ARC project?

Discussion in 'iOS Programming' started by xArtx, Feb 6, 2013.

  1. xArtx, Feb 6, 2013
    Last edited: Feb 6, 2013

    xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #1
    Hi,
    I used "Analyse" on an ARC project, and see three warnings which are the
    "Memory is never released, potential leak of memory pointed to by byteData".

    What gives?

    it's talking about this:
    Code:
        // Check if the file already exists
        if ([filemgr fileExistsAtPath: dataFile])
        {
            // Read file contents and display in textBox
            NSData *databufferx;
            databufferx = [filemgr contentsAtPath: dataFile];
            
            NSUInteger len = [databufferx length];
            Byte *byteData = (Byte*)malloc(len);
            memcpy(byteData, [databufferx bytes], len);        
            
            // copy file into second half of array
            for (int ix = 0; ix < len; ix++) { 
                memoryfile[ix+1337481] = byteData[ix];
            }        
         
            
        }  
    
    Given it's an ARC project, I thought I can't release it if I wanted to.
    At this point in the program, I am finished with everything except for memoryfile.
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    ARC only handles Obj-C objects. It does not handle C data. You'll need to manually release any C / CoreFoundation data.
     
  3. xArtx, Feb 6, 2013
    Last edited: Feb 6, 2013

    xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #3
    Ah.. thanks, that explains it.

    How obvious is it?
    Code:
    free(byteData);
    
    I hope this is not what happens as you learn Obj-C :D
     
  4. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    On a related topic... Does ARC handle destroying C++ objects? I've noticed that when you make a new C++ project the ARC checkbox is still available... I'm wondering if that's a bug and it's not actually an option or a feature and it does work with C++.
     
  5. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #5
    Couldn't tell you sorry, It was always plain C for me,
    but I imagine you can still use Apple UI stuff, and the option should be there for that.

    Shouldn't be hard to create something, Analyse the project,
    and see if Xcode complains. That's how I found out.
     

Share This Page