Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / July 2006



Tip: Looking for answers? Try searching our database.

Memory Leak Issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bala - 24 Jul 2006 12:06 GMT
Hi all,

I am getting memory leak on the following statement.

CFHTTPMessageRef httpRequest=
CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"),
CFURLCreateWithString(kCFAllocatorDefault,
CFStringCreateWithCString(kCFAllocatorDefault, requestString,
kCFStringEncodingUTF8), NULL), kCFHTTPVersion1_1);

requestString - is the complete request string its a CString
In this statement im only releasing requestString.

Can somebody tell me what are the thning I have to deallocate to solve
the memory leak.
other than requestString I hav not allocated any other stirng so do I
really need to dealloce any of the strings.

Thanks,
Bala
Gregory Weston - 24 Jul 2006 12:54 GMT
> Hi all,
>
[quoted text clipped - 16 lines]
> Thanks,
> Bala

For the most part, any time you call a function that has "Create" in the
name you're going to have to call CFRelease somewhere down the line.
There are a couple of cases where a function that you'd pass such an
object to will consume it - take responsibility for one decrement of the
ref count - but those are very rare and documented. So I'd say that
you'll need to release httpRequest and the URL that you're passing as
the third argument to CFHTTPMessageCreateRequest.

Signature

What I write is what I mean. I request that anyone who decides to respond
please refrain from "disagreeing" with something I didn't write in the first
place.

David Phillip Oster - 25 Jul 2006 15:50 GMT
> Hi all,
>
[quoted text clipped - 13 lines]
> other than requestString I hav not allocated any other stirng so do I
> really need to dealloce any of the strings.

Gregory is right. Should be:

CFStringRef s = CFStringCreateWithCString(kCFAllocatorDefault, requestString, kCFStringEncodingUTF8);

CFURLRef url = CFURLCreateWithString(kCFAllocatorDefault, s, NULL);
CFRelease(s);

CFHTTPMessageRef httpRequest=CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"),
url, kCFHTTPVersion1_1);
CFRelease(url);

...

CFRelease(httpRequest);

You can release objects immediately after you use them, since the object
that uses them will retain them while it is using them.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.