I've been tracking down a memory leak for a little while now. I have isolated it to
unmanaged memory, and what appears to be inside Crystal Reports
ExportToStream method (using Crystal Report XI Release 2, VS 2005, .NET 2.0).
My service produces a large number of reports as pdf's, and at about 10,000 I'm running out of memory. Mind you, my report is rather large (approximately 18 pages), but I'm currently leaking approximately 33k per report. My datasets and report objects are wrapped in usings, and
all managed memory heaps are kept in check. The main culprit appears to be ExportToStream.
Here's the sample code:
using (DataSet dst = new DataSet())
{
dst.ReadXml(@"c:\temp\data.xml", XmlReadMode.ReadSchema);
using (ReportClass rpt = new TestReport())
{
rpt.SetDataSource(dst);
rpt.Refresh();
using (Stream stm = rpt.ExportToStream(ExportFormatType.PortableDocFormat))
{
}
rpt.Close();
}
If I comment out the ExportToStream, my managed and unmanaged memory is fine. If I leave it in, my unmanaged memory grows until I eventually run out.
I'm currently using MemProfiler to keep track of the memory, and it brought up that
there are EventHandlers that remain attached, and are not being released. The only problem is that it appears to be deep in Crystal Reports code. It's complaining about events on
InternalEnterpriseLogonInfo - ReportID - ReportClientDocumentWrapper. Has anyone else experienced this?
These events are different than the old Crystal events bug as reported here:
[
Crystal memory leak]
My next thought is to try to force this to run in it's own memory space somehow, but I'm not sure how to do that.
Any ideas on a solution or work around?