Memory leak problem

Discussion in 'iOS Programming' started by diyora, Oct 8, 2008.

  1. diyora macrumors newbie

    Joined:
    Jul 21, 2008
    #1
    Hello all,

    I have written following code:

    Code:
    		NSURL *theURL = [NSURL URLWithString:strURL];
    		NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0f];
    		[theRequest setHTTPMethod:@"POST"];
    		[theRequest setHTTPBody:streamBuffer];
    		
    		NSURLResponse *theResponse;
    		NSError *theError;
    		NSData *theResponseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];
    
    But i got a memory leak when execution completes.
    These are two memory leaks that i don't able to understand:

    1. NSMachPort
    2. CFRunLoopSource

    Any body have any idea about this, please let me know.

    thanks in advance.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    There is a well known leak in Apple's code for sendSynchronousRequest. Use the asynchronous methods instead. If you do a search on this forum you will find other examples of people reporting this.
     
  3. diyora thread starter macrumors newbie

    Joined:
    Jul 21, 2008
    #3
    Thanks for your quick reply.

    Did you have any sample for asynchronous methods for sending url request.

    I want to pass my data to delegate function as well.

    Thanks.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    It's in the documentation. Or do a search.
     
  5. ploppy macrumors newbie

    Joined:
    Jan 13, 2007
    #5
    sendSynchronousRequest: only leaks 128 bytes. Don't worry about it unless you're doing it a million times or something.
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    How many bytes does it have to be before you worry? Personally I think this is a terrible attitude to have and will, almost certainly, show through in sloppy programming elsewhere. It's easy to work around and prevent this leak so there is no reason not to.
     
  7. Pulkit macrumors newbie

    Joined:
    Aug 27, 2008
    #7
    robbieduncan, can you tell me where I can find the list of apple apis which have leaks? Actually in my application I am using "NSXMLParser parse" and everytime I run instruments and see leaks in my code it shows me "NSXMLParser parse". So, It's my perception that api might also be leaking some memory.

    Any ideas?
     
  8. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #8
    There is no such list. You need to investigate each leak on it's own merit. If there is a leak in Apples code it tends to get reported on the web (use Google).
     
  9. matthewmccull macrumors newbie

    Joined:
    Jan 16, 2009
    #9
    Aggregated Details on this sendSynchronousRequest Leak

    I've posted a blog entry with a large quantity of aggregated details about this 128 byte leak problem. I've also submitted another radar defect with Apple (bug# 6503844) about this. Details and my full summary here.
     

Share This Page