login about faq

I'm using I use CkSettings::cleanupMemory() at the end of my MFC dialog based program but still get memory leaks when the program exits.

I'm using a simple call to CkHttp in a separate thread. Without that call there are no memory leaks.

I've tried calling cleanupMemory() at the end of the thread and at the end of the program, neither seem to work...

asked Nov 14 '12 at 03:21

ofransen's gravatar image


I've tried this too:

const char* const pszReply = http.quickGetStr(szCloudAddress);

if (pszReply != NULL) { TRACE ("Web result=<%s>n",pszReply) ; delete [] pszReply ; }

ifdef _DEBUG

// Try cleaning up in the thread


_endthreadex (0) ; // Do you need this????

return (0) ;

But still leaking. I must have missed something...

(Nov 14 '12 at 09:20) ofransen

If making a Chilkat method call that returns an object, such as a "CkHttpResponse *" object, make sure to delete it before your program exits. For example:

CkHttpResponse *resp = http.SynchronousRequest( ...  );


delete resp;

answered Nov 14 '12 at 08:09

chilkat's gravatar image

chilkat ♦♦

I'm not using pointers, just the local stack. I've narrowed it down to this:

CkString html;
return (0) ; // without this I get memory leaks

// This appears to be the leaker
html = http.quickGetStr(szCloudAddress);

TRACE (L"Web result=<%s>\n",(const wchar_t *)html) ;

_endthreadex (0) ;

Surely I don't have to delete the CkString?

(Nov 14 '12 at 09:10) ofransen

If it's truly a memory leak in Chilkat, then it should be equally reproducible in a simple single-threaded example. In other words -- remove the complexity so that nothing else can be the problem. Write a very simple program that demonstrates the leak. For example:

void leakTest(void)
    CkHttp http;
    bool success = http.UnlockComponent("test");
    const char *html = http.quickGetStr("http://your_url_here");

#if defined(WIN32) int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) #else int main(int argc, char *argv[]) #endif {
// // All Chilkat objects need to have been destructed prior to calling CkSettings::cleanupMemory. // This is why the CkHttp object is placed in a function, so that when the function returns, // the CkHttp object is destructed.
// #if defined(WIN32)
_CrtDumpMemoryLeaks(); #endif

return 0;



answered Nov 14 '12 at 10:54

chilkat's gravatar image

chilkat ♦♦

edited Nov 14 '12 at 10:57

The answer it seems is that calling _endthreadex (in a separate thread from the main MFC one) creates the memory leaks.

Maybe the problem is that _endthreadex finishes the thread before cleanupMemory gets a chance to finish. A mystery wrapped in an enigma!


answered Nov 15 '12 at 00:32

ofransen's gravatar image


Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Nov 14 '12 at 03:21

Seen: 2,129 times

Last updated: Nov 15 '12 at 00:32

powered by OSQA