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.