I have to load an WPF User Control in an MFC Dialog that is being invoked from the ocx control. For this I have created a MFC Regular Dll(Mixed Mode Regular dll with clr option enabled), I have created a Dialog in this which hosts wpf user control using HWndSource. This exported dialog is placed as a child Dialo开发者_高级运维g of thr above MFC dialog that is being invoked from the ocx. Ny intermediate dialog uses C++/Cli code.
When the main MFC dialog is closed, I am deleteing the ptr reference of the intermediate dialog created on the heap.But there after I still see a continous memory leak or growth. In the destructor of the dialog, I am calling the delete on the HWndSource and the the wpf user control, so that its dispose should be called.
But I see a continuous leak there after.
Any help in this regard would be helpful.
Could see some issues in google, with a continuous leak of 4kb when using HWndSource. My problem seems to be simialr to that.
WPF Memory Leak on XP (CMilChannel, HWND)
I have simulated this issue in a sample MFC Dilaog Application which is in similar to my actual development application. In the applications's constructor, I have created a dummy HWndSource object first and it seems to show an improvement in the leakage of memory.
I have added another exported function in my clr enabled intermediate mfc regular dll which creates the HWndSource. I am calling this exported function from my application's constructor.
void CConnectionPanelExport::CreateHwndSource()
{
HWND hwnd = (HWND)(gcnew System::Windows::Interop::HwndSource(*gcnew
System::Windows::Interop::HwndSourceParameters("MyApplication")))->Handle.ToPointer();
CWnd *temp= CWnd::FromHandle(hwnd);
temp->ShowWindow(SW_HIDE);
}
From My Application's constructor, I Called
CConnectionPanelExport connectionPanelExport;
connectionPanelExport.CreateHwndSource();
This seems to keep the application's memory in control, but really I could not understand the probelm.
I have tried implementing this in my actual development application and I see application is getting closed when I am calling this exported method of /clr enabled dll. I am making a static linking of the clr enabled dll in a non clr enabled main application
精彩评论