ReportViewer Memory Leak

It would appear that the ReportViewer control has a memory leak.

Create a new windows project with two buttons labeled 'Go' and 'Collect' with the following event handlers:

private void btnGo_Click(object sender,EventArgs e)
{
using (LeakyForm form = new LeakyForm())
{
form.Show();
}
}

private void btnCollect_Click(object sender,EventArgs e)
{
GC.Collect();
MessageBox.Show(GC.GetTotalMemory(true).ToString("#,###,###,###"));
}

Add another form to the project named LeakyForm and put a ReportViewer control on it. Run the app and you should see it leak about 50K bytes each time you press the 'Go' button and then close that form.

The situation gets much worse if you actually load reports and data into the viewer.




Answer this question

ReportViewer Memory Leak

  • TinyDev

    I have gotten OutOfMemeory exceptions while working in the designer fairly regularly now.  I'm not sure what exactly is doing it, whether its the designer or the Report Viewer I'm using during testing, but its annoying for sure.  All of this is rather strange seeing that my machine seems to have plenty of resources and I have 4GB of RAM installed.


  • cm6043

    I reported one variant of how this leak occurs yesterday on Microsoft Connect. In my analysis using windbg and gcroot, it was traced to the ToolStripTextBox+ToolStripTextBoxControl registering the event on multiple visible requests. An independent analysis was also documented at http://www.scitech.se/blog/index.php/2007/10/05/memory-leak-in-toolstriptextboxcontrol/
    (which I also referenced in the report to microsoft).



  • Alex_Mann

    Hello all,

    We are experiencing the same problem, an we are in July 2007 now. The canonical form of the problem seems as follows:

    UserPreferenceChanged Evebt Handler is still subscribed after the form is closed.

    Hope to get an answer from the Microsoft team.

    Greetings,

    Sarper Gurel


  • RayHerring

    Hello all,

    Could someone tell me where Sarper Gurel found that the report viewer subscribe to UserPreferenceChanged Event . I really spend ours find it without any good results.





  • dcd112778

    I wish the temp file leak was only 50K.
  • Kevinadian

    wow... Nearly 80 views on this thread and not a single comment. Anyone else seeing this issue

    I put up a program stub if someone wants to play around with this. It consisits of 2 forms, 2 buttons and a report viewer control and can be downloaded at http://www.strawhatfarm.com/LeakStub.zip


  • ReportViewer Memory Leak