Unmanaged memory but perfmon result differs

Memory profiling for .NET developers

Moderators: Luke Jefferson, StephenC, AndrewH, melvyn.harbour, james.billings, Laura Morley, dene.boulton

Unmanaged memory but perfmon result differs

Postby ngodugu » Tue Feb 15, 2011 9:04 pm

Hi All,

I used the red gate memory profiler to profile my app and Redgate showed about 1.3GB in unmanaged memory. That is huge.

After going nowhere with redgate as it was unmanaged memory, I used perfmon to track the following counters on my app.

Total Bytes in all heaps (.NET CLR Memory)
and
Private Bytes(Process)

This showed that in fact it was Total Bytes in all heaps that was growing and from what I have read this indicates a managed memory leak.

What gives with the unmanaged memory being shown in the redgate tool?

How should I proceeed?

Thanks in advance
Neelima
ngodugu
 
Posts: 6
Joined: Mon Jan 31, 2011 9:33 pm

Postby AndrewH » Wed Feb 16, 2011 3:21 pm

The report on unmanaged memory in ANTS Profiler is all memory that is private, committed and not allocated to .NET. When added to the .NET memory usage, it will correspond roughly to the private bytes performance counter.

.NET 1.1 doesn't report the amount of unused memory in the heaps it is using to the profiler, so unused .NET memory will be reported as unmanaged in this version of .NET as the profiler can't distinguish it (in .NET 2.0 and later, this is reported as 'free' memory and properly subtracted from the 'unmanaged' measurement).

I think that the # bytes in all heaps counter does include unused heap memory in .NET 1.1, so you can still work out the amount of free memory from that. A high proportion of free to used memory is a classic sign that your application is suffering from issues caused by heap fragmentation.

Note that the # bytes in all heaps performance counter is misleading and often doesn't report an accurate value as it's only updated after a garbage collection. Most commonly, it reads too low but there do seem to be circumstances where .NET will release memory without updating the counter, which causes it to read too high. Taking a snapshot performs a full garbage collection, so will force this counter to update to the correct value.
Andrew Hunter
Software Developer
Red Gate Software Ltd.
AndrewH
 
Posts: 134
Joined: Thu Aug 17, 2006 3:44 pm

Postby ngodugu » Wed Feb 16, 2011 11:05 pm

Andrew,

Thanks for the prompt and detailed reply. How do we proceed from here using red gate profiler to figure out if there is a memory leak. As the unmanaged memory is not accounted for the in the class list.

Thanks
Neelima
ngodugu
 
Posts: 6
Joined: Mon Jan 31, 2011 9:33 pm

Postby AndrewH » Mon Feb 21, 2011 12:29 pm

Hi,

It really depends on what you think the problem is. If you're running on .NET 1.1 and you suspect fragmentation, you should probably start by reading this article, which describes how the situation arises:

http://www.simple-talk.com/dotnet/.net- ... ject-heap/

If you can get your application running on .NET 2.0 for the purposes of profiling, you will have an easier time of debugging this issue as the profiler can provide more information.

Fixing these problems tends to be rather involved. You can find which objects are on the large object heap using the filter panel: almost certainly this will be some arrays. You will need to either change the order in which these are allocated so that all the long-lived arrays are allocated early on in the program's lifetime, or work out how to substitute arrays that don't end up on the large object heap.

If the problem is actual unmanaged memory usage, the memory profiler won't be able to help if the component with the leak is itself unmanaged. If you aren't using your own or any third-party unmanaged components, this is fairly unlikely, however. If the problem is .NET components that reference unmanaged objects, you just need to find the leaked .NET components and fix them to reduce the unmanaged memory usage. You can do this by looking at the instance counts. I posted a possible strategy for this here:

http://www.red-gate.com/MessageBoard/vi ... hp?t=12658
Andrew Hunter
Software Developer
Red Gate Software Ltd.
AndrewH
 
Posts: 134
Joined: Thu Aug 17, 2006 3:44 pm


Return to ANTS Memory Profiler 7

Who is online

Users browsing this forum: No registered users and 0 guests

cron