Memory usage issue in WPF application with C++ DLL
Asked Answered
N

0

11

I have a C++ dll which reads the certain file format. If I use this dll using WPF application it consumes 1Gb of memory but if I use the same dll using MFC application it uses 200Mb of data.

My initial guess is it is taking some memory while dynamic memory allocation although I am not sure. I know that its hard to guess the possible culprit without code . All I want is there any checks I can do to make sure that I am not missing any settings which I should have used or any suggestion which might help.

And yes I did try various Profile none of them shows any memory leaks.

UPDATE : Using procdump I get to know more detail about memory consumption. Below is the snapshot of the output of DebugDiag analysis report. It shows virtual memory consumption of 2.23 GB for WPF app with C++ dll and for MFC app with C++ dll it shows 60MB.

DebugDiag report snapshot

Nonconformance answered 31/10, 2017 at 14:56 Comment(14)
Do you consume C++ code as COM or you use C wrappers to work with the library?Danyluk
we use it as wrappers!Nonconformance
Well, could be a popular leak in COM if you used it) But you don'tDanyluk
just out of curiosity which Popular COM leak you are talking about ?Nonconformance
var a = c.GetB().GetA(); and forgetting that result of GetB() shoulf be ref counted and released. At least thats's what I've seen the most.Danyluk
The real memory usage is the "mapped" one, isn't it? What's the value for the "mapped memory" in the MFC case? Btw, 8 TB Memory? What kind of machine is this?Cantor
Did you try GC.Collect(); on occasion?Tomsk
I used to use .Net memory profiler to find memory-related issues. Really liked the tool. It has evaluation period so I suggest you give it a try. For me, it helped to finish a month-long chase of simple typo - there was += instead on -=.Arachnid
@Rahulgalgali Are you dsiplaying some information on Screen USing WPF ? What control exactly u use?Offal
If your passed data consists of a lot of 8-bit strings, the .NET marshaller is going to triple your memory consumption there at the very least. In cases where the strings are input and output, I believe it will quadruple it. At least that would be the case in a typical no-brainer wrapper where you will receive UTF-16 copies of the original data. Just a thought.Beneath
When you are consuming C++ (or other unmanaged code) you should be use "using" statements or cal "IDispose" interface for clear memory leaks. Example of "using statement" with unmanager resources: #4718289Keely
5x sounds like the number of threads that are running in a managed app vs in a native app. Perhaps your DLL does something on DLL_THREAD_ATTACH that results in all the memory, and it's happening more times in the managed app because there are more threads?Konya
I would use umdh tool from Debugging Tools for Windows to look at top heap allocation stacksSiusiubhan
This is not a memory leak, you have the the answers here, it is a combination of marshaling and disposing. I suggest to stop using the COM interface and instead write managed wrapper consuming the native library directly.Mccluskey

© 2022 - 2024 — McMap. All rights reserved.