Skip to Content
0
Former Member
Mar 01, 2012 at 08:33 AM

Memory Leak .NET 4.0 SP2 WPF Crystal Report Viewer

192 Views

My question is the same as this closed but unanswered Question

[http://forums.sdn.sap.com/thread.jspa?threadID=2086323|http://forums.sdn.sap.com/thread.jspa?threadID=2086323]

XAML

<Window x:Class="MyProject.Reports.ReportViewer"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:cr="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"
        Loaded="CrystalReportViewer_Loaded"
Unloaded="Window_Unloaded"
        Title="WPF Crystal Report Viewer" Height="600" Width="800" >
    <Grid>
        <cr:CrystalReportsViewer Name="vwCrystalReportViewer"/>
    </Grid>
</Window>

Code Behind C#

public ReportViewer()
        {
            InitializeComponent();
         vwCrystalReportViewer.Owner = this;
        }
private ReportDocument objRptDoc;
 private void CrystalReportViewer_Loaded(object sender, RoutedEventArgs e)
        {
    DataDictionary reportDictionary = new DataDictionary();
                    reportDictionary.Load();
objRptDoc =(ReportDocument)reportDictionary;
 //Configure The Report for the Data Connections - Before Parameters
                    objRptDoc = ConfigureReport(objRptDoc);

                    //Assign the Report as the Viewers Record Source - Before Parameters
                    this.vwCrystalReportViewer.ViewerCore.ReportSource = objRptDoc;
.... Add Parameters
 this.vwCrystalReportViewer.ViewerCore.ParameterFieldInfo = Params;
  //Display the Report
                        this.vwCrystalReportViewer.ViewerCore.ToggleSidePanel = SAPBusinessObjects.WPF.Viewer.Constants.SidePanelKind.None;
                        this.vwCrystalReportViewer.ViewerCore.Zoom(75);
                        this.vwCrystalReportViewer.ViewerCore.ReuseParameterWhenRefresh = true;
                        this.vwCrystalReportViewer.ViewerCore.EnableRefresh = true;
}
 private void Window_Unloaded(object sender, RoutedEventArgs e)
        {
           
            foreach (CrystalDecisions.CrystalReports.Engine.Table table in this.objRptDoc.Database.Tables)
               table.Dispose();
            objRptDoc.Database.Dispose();
            objRptDoc.Close();
            objRptDoc.Dispose(); 
            this.vwCrystalReportViewer.ViewerCore.Dispose();
            GC.Collect();
     }
   }

The issue is that the application which uses this report window is used many times and memory usage for the application goes shooting up to 700+mb causing slowness of the application and Arithmetic Overflow errors when a number of reports have been opened and closed

Using ANTS Memory Profiler the ReportViewer window is being held open by the IWindowService

HasContent = True

and I have been desperately trying to remove thie report viewer from the open forms.

I Dont care if the DLL's are still loaded to untill the app closes, I do have an issue if the window is not released from memory!

HELP this is a major issue for my client as it is crashing the application!!!

I cannot have the same window and load report in same viewer as there are times when they need 2 or meore reports open at any one time

PLEASE what do I need to to to resolve this!!