Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

diyora

macrumors newbie
Original poster
Jul 21, 2008
25
0
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.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
 

diyora

macrumors newbie
Original poster
Jul 21, 2008
25
0
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.

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.
 

ploppy

macrumors newbie
Jan 13, 2007
10
0
sendSynchronousRequest: only leaks 128 bytes. Don't worry about it unless you're doing it a million times or something.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
sendSynchronousRequest: only leaks 128 bytes. Don't worry about it unless you're doing it a million times or something.

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.
 

Pulkit

macrumors newbie
Aug 27, 2008
25
0
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.

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?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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?

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).
 

matthewmccull

macrumors newbie
Jan 16, 2009
1
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.