Help interpreting unmanaged memory size reporting

sgorozcosgorozco Posts: 2 New member
edited October 16, 2018 6:08PM in ANTS Memory Profiler 8
Could someone explain me what I'm interpreting wrong? I am seeing what seems to be an unamaged memory leak in our code. The summary window shows the Allocated by managed code counter steadily climbing between snapshots. (e.g. a 1-minute gap between snapshots, shows a positive difference of ~20-40KB).  However, when I go to the managed class list and order the results by Unmanaged Size, only a few class types are holding to unmanaged memory and their combined size does not add up to the total reported on the Summary Window, futhermore, their reported consumption sizes do not vary between snapshots. I have no class filter applied. 

The solution does make use of several C++/CLI modules. Could that be the problem?

Best Answer

  • Jessica RJessica R Posts: 1,210 Rose Gold 4
    Accepted Answer
    Hi @sgorozco,

    Thanks for your post!

    The value for unmanaged memory "Allocated by managed code" accounts for the memory allocated directly by managed code via MarshalAllocHGlobal or similar methods.

    When you take a look at the class list, you can see how much unmanaged memory each managed class references via the "Unmanaged size" column. In theory, all the values under the "Unmanaged size" column should add up to the "Allocated by managed code" value in the breakdown. However, the profiler can't always associate unmanaged memory with the classes that referenced it, so the column values can often add up to less.

    The reason for this: the profiler calculates the size of unmanaged memory associated with a .NET object (the value shown in the "unmanaged size" column) by checking the object for IntPtrs that are associated with particular unmanaged allocations. However, it can't always associate unmanaged memory with instances that reference it. One example is if the IntPtr to unmanaged memory is contained within a struct.

    With that, are you able to do a search through your code and its dependencies to check for calls to "intptr" or "MarshalAlloc"?

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


Sign In or Register to comment.