cancel
Showing results for 
Search instead for 
Did you mean: 

Memory leak issue when using Crystal Reports for VS 2010 with .Net

Former Member
0 Kudos

I upgraded to VS 2010 and installed CRforVS_13_0.exe

after doing this, each time I run a crystal report, Memory Useage goes up by 0.4 GB.

After running the report 5 or 6 times I get a memory error and have to close my application down.

I have tried cr4vs2010.exe but this is a beta version.

I am using c#

I create a DataSet and use the code this way:

myReport.SetDataSource(myDataSet);

myReport.Export();// create the RPT

myReport.Close();

myReport.Dispose();

This is the same code I used for VS 2008 with .Net and there was no significant memory leak.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I called Database.Dispose();

I also close and dispose the subreport(s) but none of this seems to make any change.

I call DataSet.Clear(); and DataSet.Dispose();

If I run my code without passing my dataset to the crystal report I have no memory leak.

I am using .Net Framework 4

My report is currently set to No printer, and I don't set it because I am exporting the report as an *.RPT file.

My default printer is set to "Send to one Note 2007"

I changed my printer to an HP printer and had the same result.

I am using Windows Task Manager to view the memory usage.

I use .Load SOS.dll and !dumpheap u2013stat to see what classes are not getting removed.

The error message that I get is: Exception of type 'system.OutOfMemoryException' was thrown.

0 Kudos

Hello,

Great info.....

One more test, rather than using a Data set can you use an OLE DB connection to the database. This is for testing only to see if it's the DS driver causing the problem. Or use ODBC, anything other the the ADO.NET driver which is the database driver I assume you are using.

How many rows of data are you returning?

One problem with using the ADO.NET driver is it is very memory intensive. Microsoft for security reasons do not allow you to connect to the DS directly bu makes a copy for third party's to use and therefore you double the amount of memory required. It also explains why we don't recommend using that driver for reports that consume a large amount of data. 10K row is absolute max to ever use. If you need more then it is much more efficient to hit the DB directly either through Stored Procedures or Views or temp tables.

Thank you

Don

Former Member
0 Kudos

Sorry,

I construct the DataSet by hand.

It would take weeks of work to duplicate this using stored procs.

0 Kudos

Sorry?

Try any different database driver other than a dataset, doesn't matter if it's your data. We just want to see if it's the DS causing the leak.

Again... How many rows of data are you using?

Thank you

Don

Former Member
0 Kudos

"Sorry" means that I can't just run this using a different database driver without taking a large amount time. It would take weeks to do this. (unless I'm wrong and there is a way to take a DataSet and pass it to the RPT without using ADO.NET)

note: all of the crystal reports that I use have this problem. The amount of memory that is leaked will change based on the size of the dataset that is used.

one report uses about 21 rows of data plus a medium size bitmap. this only leaks 0.06 GB

The number of rows on the largest one is hard to calculate because the report has 6 sub-reports.

lets just say it is large. The report uses 10 data tables and creates 21 different Types of rows of data.

some of the data is used to tell the report HOW to display the data but it is stored in a data table.

Once the *.RPT file is created, I do not notice a memory leak when I preview or print it.

former_member208657
Active Contributor
0 Kudos

note: all of the crystal reports that I use have this problem. The amount of memory that is leaked will change based on the size of the dataset that is used.

one report uses about 21 rows of data plus a medium size bitmap. this only leaks 0.06 GB

Before we jump to "memory leak" I think we should look at memory usage by the Crystal Reports engine. I noticed in your last reply you mentioned that you are using a medium sized bitmap in your data. I want to point out that Crystal Reports is not efficient at handling images and tends use a lot of memory when processing them. I saw a case the other day where one report used 500 MB of memory because of one image in the report.

As a test, remove or hide the images in your report design. See if this makes a difference. If it does, try and reduce the quality of your images to save on memory usage.

Are the images of logos or product images? Or is the image used as a type of form template?

0 Kudos

Hi Karlus,

In your application what you can do is use this to get your data into XML format:

ds.WriteXmlSchema("c:
sc.xml", "c:
sc.xsd");

But the easiest way is to export the report to ODBC from the viewer. Create a DSN to either SQL Server or Access and then export. You can now use it as your data source.

Another way is to copy your existing report then take the original and save it or export it to RPT format which will save it with data. You can now use the report with saved data as a data source.

Bottom line is use any report based on any driver other than the one you are using, OLE DB or ODBC and then watch the memory again to see if it's the driver causing the issue.

SAP takes memory leaks VERY seriously so I would be very surprised if this is CR "leaking" the memory and not some dependency.... There are third party tools out there also that can test and track memory leaks. I believe you'll find it is a MS dll that is leaking but it is possible it is a CR issue... We just need to prove it and so far I don't see it.

Thank you

Don

Former Member
0 Kudos

> Another way is to copy your existing report then take the original and save it or export it to RPT format which will save it with data. You can now use the report with saved data as a data source.

right now I use this code to load the saved *.rpt

myReport.FileName = path + "saved.RPT";

myReport.Load();

if I print or preview this loaded report I see no leak.(I see the leak when the *.rpt is created)

if this is not what you mean, then how do I use "myReport" as a data source?

This code does not work: myTestReport.SetDataSource(myReport.Database);

"[Don]"

Sorry, my mistake... It was going to be a feature to use a report with saved data as a data source but it was removed for some reason.... Not an option now. Only way would be to export to ODBC.

Edited by: Don Williams on Dec 15, 2010 11:13 AM

Former Member
0 Kudos

It WAS the move from .Net 3.5 to .Net 4

I compiled for .Net 3.5 and the memory leak went away!

0 Kudos

Hello,

Can you add this to your app.config file:

<startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

And set your framework back to 4.0 and see if this resolves the problem?

Thank you

Don

Former Member
0 Kudos

It was all ready set to that.

(still have the problem in .Net 4)

0 Kudos

What happens if you add:

GC.Collect as the last line to force Windows to do the memory release, could be the Windows holding onto the allocated block of memory:

myReport.SetDataSource(myDataSet);

myReport.Export();// create the RPT

myReport.Close();

myReport.Dispose();

GC.Collect();

Thank you

Don

Former Member
0 Kudos

calling GC.Collect(); does not make any difference.

Former Member
0 Kudos

I added GC.Collect(); before, I donu2019t know why it is working now (or why it didnu2019t work then.)

but GC.Collect(); works!

Thank You!

Answers (2)

Answers (2)

Former Member
0 Kudos

Have the same problem. Updated production server to ASP.net 4, started getting out of memory exeptions throughout the application within 2 hours. Reports and code are the same, only difference is targeting the .net4 framework rather than 3.5. Using latest runtime from CR2008

Crystal errors appeared:

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> CrystalDecisions.Shared.CrystalReportsException: Load report failed. ---> System.Runtime.InteropServices.COMException: Failed to open report.

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> CrystalDecisions.Shared.CrystalReportsException: Load report failed. ---> System.Runtime.InteropServices.COMException: Not enough storage is available to process this command.

occurred on other pages:

Oracle.DataAccess.Client.OracleException Memory could not be allocated

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

[Don]

Replying directly in your post to clarify. CR 2008 does not support 4.0 framework nor does VS 2008. VS 2010 does not support CR 2008 runtime.

Don

Edited by: Don Williams on Dec 14, 2010 10:35 AM

former_member183750
Active Contributor
0 Kudos

This thread is specific to CR2010 (Memory leak issue when using Crystal Reports for VS 2010 with .Net). Your issue appears to concern CR 2008:

Using latest runtime from CR2008

I don't think the two issues are related - other than a similar behavior. Please create a new thread.

Ludek

Former Member
0 Kudos

When we changed to VS 2010 we also went from .net 3.5 to .net 4

so it could be the move to .net 4

I am going to compile for 3.5 and see if I have the same problem.

former_member183750
Active Contributor
0 Kudos

Are you doing .Close and .Dispose on the dataset also?

What framework are you using?

Ludek

0 Kudos

Also, as a test, set the report to No Printer. It could be the printer driver is being loaded each time but not being released. Windows takes it time to free that memory the Printer structure uses.

And what tool did you use to see the memory not being released?

What is your default printer?

Thank you

Don