need help to understand Leaks

Discussion in 'iOS Programming' started by MACloop, Mar 25, 2010.

  1. MACloop macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #1
    Hello,
    I work on an app and get indications that it contents leaks. I have read my code 1000 times and double checked every alloc/retain and releases. Til now that did not help :-(

    My problem is that I do not really understand what Instruments/Leaks "tells me". I made som screen shots in order to show you the situation. On start up, there is a leak detected. After that if do not leave the first view, it does not leak anymore. But if I use the tables in my App to navigate through the different parts of the app, some leaks appear. Those leaks only appear once each...this means after the leaks have appeared I can use the program "forever" without further leaks...

    When clicking in the detailed view in instruments ie on pic 2 and 3 in the gray cells, I get following indications for the leaks.
    Code:
    //a leak
    [[DataAccess sharedDataAccess] initWithUrls:urls andDelegate:self];
    		
    //another leak
    [self requestWithUrls];
    
    //another leak
    NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
    
    //another leak
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    
    As I said, I have gone through this code 1000 times and I do not find any leak in it. The odd thing is also, that the connection and parsing procedure is done once on start up... so I do not really understand why this is displayed as leak, lateron in the program flow...but it is of course possible that I understand those leak-indications totally wrong....please can anyone help me on this... :confused:

    MACloop
     

    Attached Files:

    • 1.png
      1.png
      File size:
      100.3 KB
      Views:
      30
    • 2.png
      2.png
      File size:
      182.2 KB
      Views:
      42
    • 3.png
      3.png
      File size:
      282.2 KB
      Views:
      29
  2. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Are you testing on the device or in the Sim? You should only do leaks testing on the device.

    Apparently the 128 byte malloc leaks that you are seeing are common and if they're real leaks they are system leaks, not due to your code.

    The leaks tool doesn't tell you where a leak exists. It only kind of tells you when a leak exists. What it tells you is that it detected a leak, and what kind of memory was leaked, and it tells you the stack trace to the place where the leaked memory block was allocated. In the typical case the leak happens somewhere else in the code than the line where the block was allocated.

    Also note that due to the way Objective-C applications are written there are often a number of objects that are part of a container so if the container leaks then all the contents of the container leak. So you see a lot of objects in the leak report. When you fix the leak of the container you fix the leak for all the contents.

    I'm guessing that the first stack trace you show isn't your fault but the third one is your fault.
     
  3. MACloop thread starter macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #3
    Thanks for another excellent answer! Well, I acually was testing on the sim...but I will do the same thing on the device right away to see how that looks like. I probably come back later ;-)
    Thanks alot!
    MACloop
     

Share This Page