Problem with NSURLConnection sendSynchronousRequest

Discussion in 'iOS Development' started by johnmabassa, Jun 21, 2009.

  1. johnmabassa

    johnmabassa Member

    Joined:
    Mar 16, 2009
    Messages:
    87
    Likes Received:
    0
    Hi,

    I have written a common function in my code which is called whenever I want to connect to backend here is what I am doing

    Code:
    	NSURL *urlString = [[NSURL alloc] initWithString:url];
    	NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:urlString cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10];
    	[urlString release];
    
    	NSData *myData = [[NSData alloc] init];
    	NSURLResponse *response;
    	NSError *error = [[NSError alloc] init];
    	urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
    	NSString *result=[[NSString alloc] initWithData:myData encoding:NSASCIIStringEncoding];
    [urlRequest release];
    
    I am getting the values that I wanted, but the problem is that I am getting lots of leaks from these part of code. i have tried using NSAutoReleasePool too but no result. am I doing anything wrong here?

    -John
  2. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    Code:
    NSURL *urlString = [NSURL urlWithString:url];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:urlString cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10];
    NSURLResponse *response = nil;
    NSError *error = nil;
    NSData *urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
    NSString *result= [[NSString alloc] initWithData:myData encoding:NSASCIIStringEncoding];
    Make you sure released it.
  3. johnmabassa

    johnmabassa Member

    Joined:
    Mar 16, 2009
    Messages:
    87
    Likes Received:
    0

    I tried this code, but still I am getting, memory leaks are still there. I have released all the objects that I use in this. There are lots of leaks related to CFNetWork etc only method i could point out was the above one which I was mentioning.

    It is actually a webservice call where I construct my URL and call it using NSURLConnection, and whoever wants to connect to webservice calls this method.

    I have seen many people saying about memory leaks related to NSURLConnection,NSURL etc...... some of them were saying that it is a known issue with Apple. Please let me know if there is any fix for this.

    -John
  4. johnmabassa

    johnmabassa Member

    Joined:
    Mar 16, 2009
    Messages:
    87
    Likes Received:
    0
    One important think I forgot to mention. I am running it on the simulator, not on the device. Is it like some leaks which appear on simulator wont appear on device? ( Currently i dont have the device with me to tetst, ie why I am asking)


    -John

Share This Page