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

Rahul galgali
  • 775
  • 2
  • 10
  • 26
  • Do you consume C++ code as COM or you use C wrappers to work with the library? – Sergey.quixoticaxis.Ivanov Oct 31 '17 at 15:06
  • 2
    we use it as wrappers! – Rahul galgali Oct 31 '17 at 15:47
  • Well, could be a popular leak in COM if you used it) But you don't – Sergey.quixoticaxis.Ivanov Oct 31 '17 at 15:56
  • just out of curiosity which Popular COM leak you are talking about ? – Rahul galgali Nov 01 '17 at 06:36
  • 2
    `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. – Sergey.quixoticaxis.Ivanov Nov 01 '17 at 09:12
  • 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? – geza Nov 05 '17 at 14:40
  • Did you try `GC.Collect();` on occasion? – yacc Nov 05 '17 at 18:18
  • 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 `-=`. – Alex Seleznyov Nov 06 '17 at 22:40
  • @Rahulgalgali Are you dsiplaying some information on Screen USing WPF ? What control exactly u use? – Ramankingdom Nov 07 '17 at 08:46
  • 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. – zzxyz Nov 09 '17 at 01:29
  • 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: https://stackoverflow.com/questions/4717789/in-a-using-block-is-a-sqlconnection-closed-on-return-or-exception – zchpit Nov 09 '17 at 16:07
  • 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? – Wyck Apr 04 '18 at 18:28
  • I would use umdh tool from Debugging Tools for Windows to look at top heap allocation stacks – Alex Guteniev Feb 23 '19 at 16:36
  • 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. – Hans Apr 16 '19 at 19:49

0 Answers0