Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unmanaged memory" at profiler diagram. Is this a memory leak indication?

I've faced with this diagram, when profiling memory usage of my application:

enter image description here

As you can see, before line "snapshot 1" unmanaged memory holds approximately a half of total used memory. Then, after "snapshot 1" and 2 min 55 s (see the timeline below), I've forced a garbage collection.

As I expect, generation 2 was mostly collected, but unmanaged memory was not released, and now it holds approx. 2/3 of total used memory.

I have no idea, what "unmanaged memory" means in this context. This is the WPF application with some WinForms/GDI+ interop. I'm sure, that everything, that should be disposed, is disposed. Also, there's no explicit platform interop code. The rest of managed memory is OK.

Is this a memory leak indication?
If so, what is the way to detect memory leak here?
Is this matters, the profiler I'm using is JetBrains dotMemory.

like image 393
Dennis Avatar asked Jul 20 '15 07:07

Dennis


People also ask

What is a memory profiler and how to use it?

A memory profiler is the best tool to detect these kinds of leaks. Memory leaks are extremely common in stateful applications, like in desktop applications. Stateless applications, like most web servers, are less prone to leaks because they usually don’t leave anything behind after a request finished.

How do memory profilers detect memory leaks?

Some profilers are able to import dump files. We saw that memory profilers can show all the objects in memory, their size, who they reference, who references them, and their shortest path to a GC root. That path to root is important for memory leaks because it shows why those objects weren’t garbage collected.

Is unmanaged memory profiling available in Windows?

Unmanaged memory profiling isn't available in Windows XP / Server 2003 and earlier, or when profiling .NET 1.1 applications. Before you check your application's usage of unmanaged memory, we recommend you check for fragmentation of the large object heap.

Why do unmanaged memory leaks happen in a .NET application?

Almost every developer sooner or later has to deal with the case, when the end-users or customers report that the application performs slowly, takes too much system resources like CPU, system memory, or both.


1 Answers

"Total used" memory on dotMemory chart it's the private working set of process. It's memory that the process executable has asked for - not necessarily the amount it is actually using. It includes all your DLLs and heaps but not includes memory-mapped files (shared DLLs). Moreover there is no way to tell whether it belongs to executable itself, or to a linked library. It's not exclusively physical memory; they can be paged to disk or in the standby page list (i.e. no longer in use, but not paged yet either). So, unmanaged memory is everything in private working set except managed CLR heaps. Usually you have no easy ways to change amount of unmanaged memory for pure .net process. And it's approximately constant during execution of program.

like image 142
Roman Belov Avatar answered Sep 30 '22 13:09

Roman Belov