Threads, DLL

Hi, I have a small MFC app, i have two buttons, i have a dummy function too.
I have a small dll, the issue is when i press the button 2 I have memory leak (i have tried with CMemoryState and does not detect any memory leak, but i can see it in the Process Explorer).

In my simple dll code i have in the "stdafx.h" file the following line
#include ,
but if i comment this line, the memory leak is gone.

I tried to comment all my dll code (except that include) and the problem still persists.

Any clues of this behavior?

(I tried in a Win32 application instead of MFC and i have the same problem)


void CPruebaThreadDlg::OnBnClickedButton1()
{
LPVOID lpParam = NULL;

AfxBeginThread(dummy, lpParam, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
}

void CPruebaThreadDlg::OnBnClickedButton2()
{
int i;
HMODULE hmod = LoadLibrary("SimpleDll.dll");
while(true)
{
for(i = 0; i <= 150; i++)
OnBnClickedButton1();
Sleep(700);
}
}

UINT dummy(LPVOID)
{
return 0;
}

Comments

  • you shouldn't create all those threads -- they will slow down your computer to a huge crawl. try to redesign your program to use less than 10 threads.
  • : Hi, I have a small MFC app, i have two buttons, i have a dummy function too.
    : I have a small dll, the issue is when i press the button 2 I have memory leak (i have tried with CMemoryState and does not detect any memory leak, but i can see it in the Process Explorer).
    :
    : In my simple dll code i have in the "stdafx.h" file the following line
    : #include ,
    : but if i comment this line, the memory leak is gone.
    :
    : I tried to comment all my dll code (except that include) and the problem still persists.
    :
    : Any clues of this behavior?
    :
    : (I tried in a Win32 application instead of MFC and i have the same problem)
    :
    :
    : void CPruebaThreadDlg::OnBnClickedButton1()
    : {
    : LPVOID lpParam = NULL;
    :
    : AfxBeginThread(dummy, lpParam, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
    : }
    :
    : void CPruebaThreadDlg::OnBnClickedButton2()
    : {
    : int i;
    : HMODULE hmod = LoadLibrary("SimpleDll.dll");
    : while(true)
    : {
    : for(i = 0; i <= 150; i++)
    : OnBnClickedButton1();
    : Sleep(700);
    : }
    : }
    :
    : UINT dummy(LPVOID)
    : {
    : return 0;
    : }
    :
    :

    There are two calls that creates a thread: the C-runtime's _beginthread call and the winapi CreateThread.
    It is known that the latter creates small memory leaks if your application uses the C-runtime library.
    MFC's AfxBeginThread calls CreateThread so that may be the cause of your leaks, although the leaks should be very small.


    Greets,
    Eric Goldstein
    www.gvh-maatwerk.nl

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories