Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Memory Leak in MFC?

106 views
Skip to first unread message

Anthony Wieser

unread,
Mar 5, 2009, 9:09:36 AM3/5/09
to
Are you cleaning up the thread handle?

Anthony Wieser
Wieser Software Ltd

"Georg Steigmeier" <GeorgSt...@discussions.microsoft.com> wrote in
message news:63E41D3E-276B-4303...@microsoft.com...
> By the way, I am using Visual Studio 2005 and therefore MFC 8.0.

Chris Tacke, eMVP

unread,
Mar 6, 2009, 3:14:50 PM3/6/09
to
You have the full source to MFC....

In Studio 08 it's here:
C:\Program Files\Microsoft Visual Studio 9.0\VC\ce\atlmfc\src\mfc

For '05 it was something very similar (don't have it installed to check).


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com


"Georg Steigmeier" <GeorgSt...@discussions.microsoft.com> wrote in

message news:632DD99F-CECE-4AC4...@microsoft.com...
> Hi Anthony
>
> Yes, the thread handles are closed. Another thing is, that the memory leak
> only occurs under windows CE and not under Win32. I think it's something
> inside MFC.

Georg Steigmeier

unread,
Mar 9, 2009, 11:26:06 AM3/9/09
to
Hi Chris

I find it quite difficult to debug the MFC internals. I tried to find
different behaviours between Win32 and WinCE, because the memory leak does
not occur under Win32. This is one thing I found:

If my “worker” thread (created with CreateThread) ends, then I see that the
function CThreadSlotData::DeleteValues(CThreadData* pData, HINSTANCE hInst)
[afxtls.cpp] is called from the MFC DLL and from my ActiceX control.

- Under Win32 the DeleteValues() function is first called from my ActiveX
and here no delete operation really takes place, then it is called from the
MFC DLL and the thread data gets deleted.

- Under WinCE the DeleteValues() function is called in different order.
First from the MFC DLL and the thread data gets already deleted, then it is
called from my ActiveX and here no delete operation takes place anymore. But
in between it seems that new thread data is created through calls to
CThreadSlotData::SetValue(int nSlot, void* pValue).

Do you know if the behaviour under WinCE is wrong?

Thanks in advance
Georg

Helge Kruse

unread,
May 19, 2009, 10:35:43 AM5/19/09
to
Is there any other place where you can store the ZIP file. I found no way
to open it.

Helge

"Georg Steigmeier" <GeorgSt...@discussions.microsoft.com> wrote in

message news:03D7D85B-5B20-44BD...@microsoft.com...
> Here is my code to reproduce the memory leak:
>
> http://cid-1e808bf3e2edf989.skydrive.live.com/self.aspx/.Public/MemLeakThreadProblem.zip
>
> Any help is appreciated!


Andreas Weichelt

unread,
Aug 24, 2011, 9:02:39 AM8/24/11
to
Hi,

I am facing a very similar problem. Did you find a solution (or at least workaround) in between?

Any reply is appreciated!

> On Tuesday, March 03, 2009 6:07 AM GeorgSteigmeie wrote:

> Hi
> I have a strange memory leak in my application running under CE 6.0. My
> investigations showed that it has something to do with ActiveX controls and
> starting/stopping threads.
> Now I made a test application that has the same problem. It's a simple
> dialog based application that uses MFC and has an ActiveX control on it
> (application and ActiveX generated with the wizard). The application and the
> ActiveX use MFC in a shared DLL. Now if a start a worker thread e.g. in an
> event handler inside the dialog class, then I see that the available memory
> shrinks (about 1600 bytes) after the thread stops. It doesn' matter if I use
> CreateThread or AfxBeginThread to start the thread. Note that I don' do
> anything inside the thread function, it just returns.
> I don't have this problem if I remove the (dummy) ActiveX from the dialog.
> There is also no leak if the ActiveX uses MFC in a static library.
>
> Is there a problem inside MFC?


>> On Wednesday, March 04, 2009 5:49 AM GeorgSteigmeie wrote:

>> By the way, I am using Visual Studio 2005 and therefore MFC 8.0.


>>> On Thursday, March 05, 2009 9:09 AM Anthony Wieser wrote:

>>> Are you cleaning up the thread handle?
>>>
>>> Anthony Wieser
>>> Wieser Software Ltd


>>>> On Friday, March 06, 2009 2:31 AM GeorgSteigmeie wrote:

>>>> Hi Anthony
>>>>
>>>> Yes, the thread handles are closed. Another thing is, that the memory leak

>>>> only occurs under windows CE and not under Win32. I think it is something


>>>> inside MFC.
>>>>
>>>> "Anthony Wieser" wrote:


>>>>> On Friday, March 06, 2009 9:54 AM Bill wrote:

>>>>> We had very similar behavior with CE5.0, and that MSFT recommended to us to
>>>>> preload the MFC dll "early in the WinMain. This did correct the memory leak
>>>>> we were seeing.
>>>>>
>>>>> extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
>>>>> HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
>>>>> {
>>>>> ....
>>>>>
>>>>> LoadLibrary(_T("mfcce400.dll"));
>>>>>
>>>>> ...
>>>>> }
>>>>>
>>>>>
>>>>> "Georg Steigmeier" wrote:


>>>>>> On Friday, March 06, 2009 3:14 PM Chris Tacke, eMVP wrote:

>>>>>> You have the full source to MFC....
>>>>>>
>>>>>> In Studio 08 it's here:
>>>>>> C:\Program Files\Microsoft Visual Studio 9.0\VC\ce\atlmfc\src\mfc
>>>>>>
>>>>>> For '05 it was something very similar (don't have it installed to check).
>>>>>>
>>>>>>
>>>>>> --
>>>>>>
>>>>>> Chris Tacke, Embedded MVP
>>>>>> OpenNETCF Consulting
>>>>>> Giving back to the embedded community
>>>>>> http://community.OpenNETCF.com
>>>>>>
>>>>>>

>>>>>> "Georg Steigmeier" <GeorgSt...@discussions.microsoft.com> wrote in

>>>>>> message news:632DD99F-CECE-4AC4...@microsoft.com...


>>>>>>> On Monday, March 09, 2009 11:26 AM GeorgSteigmeie wrote:

>>>>>>> Hi Chris
>>>>>>>
>>>>>>> I find it quite difficult to debug the MFC internals. I tried to find
>>>>>>> different behaviours between Win32 and WinCE, because the memory leak does
>>>>>>> not occur under Win32. This is one thing I found:
>>>>>>>
>>>>>>> If my “worker” thread (created with CreateThread) ends, then I see that the
>>>>>>> function CThreadSlotData::DeleteValues(CThreadData* pData, HINSTANCE hInst)
>>>>>>> [afxtls.cpp] is called from the MFC DLL and from my ActiceX control.
>>>>>>>
>>>>>>> - Under Win32 the DeleteValues() function is first called from my ActiveX
>>>>>>> and here no delete operation really takes place, then it is called from the
>>>>>>> MFC DLL and the thread data gets deleted.
>>>>>>>
>>>>>>> - Under WinCE the DeleteValues() function is called in different order.
>>>>>>> First from the MFC DLL and the thread data gets already deleted, then it is
>>>>>>> called from my ActiveX and here no delete operation takes place anymore. But
>>>>>>> in between it seems that new thread data is created through calls to
>>>>>>> CThreadSlotData::SetValue(int nSlot, void* pValue).
>>>>>>>
>>>>>>> Do you know if the behaviour under WinCE is wrong?
>>>>>>>
>>>>>>> Thanks in advance
>>>>>>> Georg
>>>>>>>
>>>>>>>
>>>>>>> "Chris Tacke, eMVP" wrote:


>>>>>>>> On Tuesday, March 10, 2009 4:01 AM GeorgSteigmeie wrote:

>>>>>>>> I also tried it with Visual Studio 2008 and therefore MFC 9.0. The memory
>>>>>>>> leak problem still exists.
>>>>>>>>
>>>>>>>> "Georg Steigmeier" wrote:


>>>>>>>>> On Tuesday, March 31, 2009 9:15 AM GeorgSteigmeie wrote:

>>>>>>>>> Here is my code to reproduce the memory leak:
>>>>>>>>>
>>>>>>>>> http://cid-1e808bf3e2edf989.skydrive.live.com/self.aspx/.Public/MemLeakThreadProblem.zip
>>>>>>>>>
>>>>>>>>> Any help is appreciated!

0 new messages