Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1215
Possible memory leak in pivotgrid ?
posted

I have a silverlight application containing a pivotgrid that is populated with a flatdatasource. In this particular scenario, when I set the pivotgrid.datasource property to the flatdatasource, memory usage increase by 75MB. This has been confirmed by breaking the application just before and just after the .datasource property is set. So far there is nothing unusual, as the pivotgrid has to build some internal data structures to manage the data.

The problem arise when I later set the .datasource property to nothing to empty the grid. I would then expect the memory usage to drop by the same amount (or at least close to), but this does not happen. Even more interesting, if I continue to assign new flatdatasource objects to the .datasource property, then memory usage increase with 75 MB each time, finally resulting in an out-of-memory exception.

My first question; does the pivotgrid have a method to release all internal data structures that I can call after setting .datasource property to nothing?

I have also used a memory profiling tool to play around with my application. I have isolated the objects that increase in number and memory usage between each assignment to .datasource property. The sum of these objects total growth between each assignment is close to 75 MB. The memory stack for these objects look like this:

 

Starting at the bottom of this trace with propertychangedeventhandler and working towards the root we end up with filterfielditemcontrol before going into the silverlight runtime objects. Continuing from there we encounter an eventhandler for the resized event.

Now, if I read this trace correctly it seems like filterfielditemcontrol subscribes to the resized event. When the pivotgrid at some point cleans up its internal structures the filterfielditemcontrol appears to forget to unsubscribe to this event, leaving all those instances orphaned in memory, including their stack of referenced objects.

Can you please give a comment on this, either confirming my findings and a pointing towards a fix, or advice me on how to clean up the memory usage when emptying the grid.

Thanks in advance, Mikael