Print Page | Close Window

WinForms Memory Issue

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=356
Printed Date: 24 Apr 2024 at 11:39pm


Topic: WinForms Memory Issue
Posted By: JoeBacon
Subject: WinForms Memory Issue
Date Posted: 19 Mar 2007 at 3:21pm
I am working on a c# windows forms app in Visual Studio 2005 that dynamically generates reports that contain text and images.  There is a main report and several subreports that may or may not be displayed based on user preferences.  Each report is displayed on a form using the CrystalReportViewer control.
 
What I'm finding is that each time I display a report it uses enormous amounts of memory and when I unload the form it doesn't give the memory back.  After I've displayed several reports I finally will get an exception:
 
Exception:Could not load reportSystem.Exception: Load report failed. ---> System.Runtime.InteropServices.COMException (0x80041004): Not enough memory for operation.
 
Any suggestions on how to force crystal to give back all the memory would be greatly appreciated.
 


-------------
Joe B



Replies:
Posted By: BrianBischof
Date Posted: 19 Mar 2007 at 4:01pm
I've had that happen when I haven't cleaned up objects well enough. I had to go back and thoroughly check that every report object is set to null afterwards.  However, CR has also had memory problems of its own.  Also try forcing garbage collection afterwards to make sure .NET cleans everything with the report objects. I would make sure you have the latest service packs as well. They fix bugs like this periodically.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: JoeBacon
Date Posted: 20 Mar 2007 at 1:48pm
Thanks for that response. 
 
I am using the the Crystal Reprots that comes standard with Visual Studio 2005.  How would I tell if I have the latest fixes and if not how would I download any fixes I don't have?
 
 


-------------
Joe B


Posted By: BrianBischof
Date Posted: 20 Mar 2007 at 2:16pm
go to the support site and click on the downloads link. Download the latest file and install it. I don't know the dates off the top of my head.


-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: hilfy
Date Posted: 21 Mar 2007 at 10:45am

Also, if you're using the ReportDocument object model, be sure to .Dispose() the report document in the FormClosing event handler for the viewer page.  This will free up the memory faster.

-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: JoeBacon
Date Posted: 21 Mar 2007 at 3:13pm
Thanks for that info Dell.
 
I am using the ReportDocument object model and tried the .Dispose() on the form closing and that seems to help but I still don't seem to be getting all the memory back.
 
I'm also creating DataSets using the SetDataSource() method to force the report to display the data that I want in the Main and sub reports.  I'm wondering if I need to do something get the report docuement to give up the references to the datasets.  It does seem that the amount of memory I lose on each report display is proportional to the size of the data in the dataset.  For example, one of my subreports may display several images, which causes me to "lose" a large amount of my memory.
 
 


-------------
Joe B


Posted By: hilfy
Date Posted: 22 Mar 2007 at 9:37am

I haven't done a lot of work with DataSets - just one module that gets run once a month, so I haven't' tried this...You might be able to .Clear() the DataSourceConnections property of the ReportDocument to help free up memory.

-Dell



-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics



Print Page | Close Window