Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is this growing dictionary in my Silverlight app's large object heap?
    primarykey
    data
    text
    <p>This app has a memory leak and frequently crashes the browser. I can increase its memory usage pretty quickly by repeatedly opening and closing one of the features in the app. Using ANTS Memory Profiler, I've found a mysterious growing dictionary that I don't think my app's code is directly instantiating or referencing. Can anyone provide insights into this dictionary, and/or suggestions of what to do next in order to stop the leak?</p> <p>The profiler says that unmanaged memory is growing the fastest. It has also sometimes given me a memory fragmentation alert, either "Memory fragmentation is restricting the size of objects that can be allocated" or "Memory fragmentation is affecting the size of the largest object that can be allocated."</p> <p>The biggest object on the large object heap is an array being used by a <code>Dictionary&lt;IntPtr, Object&gt;</code> that contains mostly WeakReferences. I presume that as this dictionary grows, it keeps having to reallocate its internal array (as mentioned in the Remarks section <a href="http://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.95).aspx" rel="nofollow noreferrer">here</a>); and since the GC never compacts the LOH, I'm bound to get fragmentation.</p> <p>I also wonder if this dictionary is connected to the unmanaged memory increases, since the dictionary keys are IntPtrs. I've run DebugDiag a few times with help from a <a href="http://blogs.msdn.com/b/tess/archive/2010/01/14/debugging-native-memory-leaks-with-debug-diag-1-1.aspx" rel="nofollow noreferrer">blog post</a> by Tess Ferrandez, but that gives me a whole lot of interesting information that I don't know how to analyze. Basically, the majority of the memory allocations are being done by <code>npctrl!CWindowsServices::OSMemoryAllocate</code> and <code>coreclr:CExecutionEngine::ClrVirtualAlloc</code>. Perhaps I could make the memory pressure analysis and/or .dmp file available if someone thinks that would be helpful.</p> <p><strong>[Update]</strong> I think this might be the ManagedPeerTable. See also update below. <strong>[/Update]</strong></p> <p>Here are some screen shots from ANTS. The first is from one session, and all the rest are from another session.</p> <p><img src="https://i.stack.imgur.com/pj2fZ.png" alt="Memory fragmentation"></p> <p><img src="https://i.stack.imgur.com/O1yNO.png" alt="Overview of memory changes"></p> <p>The type on the LOH with the biggest size change is an array of dictionary entries.</p> <p><img src="https://i.stack.imgur.com/P94Xa.png" alt="List of objects on the large object heap"></p> <p>Here's a list of what's referenced by the dictionary entries, most of which are WeakReference instances.</p> <p><img src="https://i.stack.imgur.com/zOsgn.png" alt="Objects referenced by dictionary entries"></p> <p>The dictionary containing these entries is itself living inside an object array.</p> <p><img src="https://i.stack.imgur.com/5UXZp.png" alt="Retention graph for array of dictionary entries"></p> <p>The object array seems to contain UI-related objects.</p> <p><img src="https://i.stack.imgur.com/lQNH8.png" alt="Contents of object array that contains the growing dictionary"></p> <p>The leaky feature has a lot of XAML associated with it, containing several custom controls, templates, styles, and a highly customized <a href="http://www.telerik.com/products/silverlight/gridview.aspx" rel="nofollow noreferrer">RadGridView</a>. So next I think I'm going to repeatedly remove pieces of the XAML and retest, and hopefully I'll narrow down a short list of possible culprits.</p> <p><strong>Update:</strong></p> <p>The more XAML I remove, the slower the leak becomes. I found that the feature's UI elements are not being cleaned up, so next I'll need to figure out why.</p> <p>The MS.Internal.ManagedPeerTable static class has a private field of type <code>Dictionary&lt;IntPtr, object&gt;</code>, and I bet that's what I'm seeing here. Apparently it's used to maintain links between unmanaged objects and the managed objects they represent. (See also this <a href="http://clivetong.wordpress.com/2011/09/05/down-to-the-mil/" rel="nofollow noreferrer">link</a>, near the bottom.) So it makes sense that if I have fewer elements in my XAML, then both the table and the amount of unmanaged memory to which it refers would grow more slowly.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload