"Insufficient memory" during merging reports

Stimulsoft Reports.NET discussion
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

"Insufficient memory" during merging reports

Post by Fabio Pagano »

Using 2009.3.523.0 version of 23 November 2009.

Scenario: i have 2.500 .mdz files of 168 KB each one (they contains images in them, "StoreImagesInResources=True") and i need to merge them in a single report, adding a blank page after each one

But about at 1/3 of the work,
i receive the error "Insufficent memory".

This is the code i use to merge these 2.500 reports in one:

Code: Select all

Dim CumulativeReport as Stimulsoft.Report.StiReport

for cicl as integer=1 to 2500
   Dim SingleReport as Stimulsoft.Report.StiReport=GetMySingleReport(cicl)

   if cicl=1 then
      'First time, assigns the cumulative report
      CumulativeReport = SingleReport
   else
      'Adds pages from single report to cumulative report
      For Each page As Stimulsoft.Report.Components.StiPage In SingleReport.RenderedPages
          CumulativeReport.RenderedPages.Add(page)
          page.Report = CumulativeReport
      Next
   endif

   'Adds a blank page
   Dim p As New Stimulsoft.Report.Components.StiPage
   p.PageWidth = CumulativeReport.RenderedPages(0).PageWidth
   p.PageHeight = CumulativeReport.RenderedPages(0).PageHeight
   CumulativeReport.RenderedPages.Add(p)

   if cicl>1 then
      'Does not dispose the first report
      'because it is the "base report".
      SingleReport.Dispose
      SingleReport=Nothing
   endif
next cicl
The error "insufficient memory" raises in "CumulativeReport.RenderedPages.Add(page)".

Am i going off limits? Is there something i can do to solve this?

Thank you.

-- edit:
I have noticed that the error often raises when i load in memory the .mdz file to create the "SingleReport" (this happens in "GetMySingleReport" function).
During processing, the memory occupation goes very high.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

"Insufficient memory" during merging reports

Post by Fabio Pagano »

I've seen that the error raises when the process reaches 1.2 gb memory. So, my question is, is there a way to have a less consuming memory when i add report pages to a cumulative report? Is there some option i can use on the report object?

The scenario is that i have about 2.500 .mdz files of 100 kb each one, to fuse in a single report.

Thank you.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

"Insufficient memory" during merging reports

Post by Fabio Pagano »

I've tried to set "CumulativeReport.ReportCacheMode=Auto" but the cache is not used (the directory has no files) so the "out of memory" exception raises.

I'm out of ideas, can you help me?

Thank you.
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

"Insufficient memory" during merging reports

Post by Jan »

Hello Fabio,

Here is sample code which provide functionality for export many reports into one bug pdf file. Sample use cache:

Code: Select all

StiReport report = new StiReport();
            report.RenderedPages.CanUseCacheMode = true;
            report.RenderedPages.CacheMode = true;
            report.RenderedPages.Clear();

            StiReport tempReport = new StiReport();
            for (int index = 0; index < 1000; index++)
            {
                tempReport.LoadDocument("d:\\2.mdc");
                tempReport.ReportUnit = report.ReportUnit;

                foreach (StiPage page in tempReport.RenderedPages)
                {
                    page.Report = tempReport;
                    report.RenderedPages.Add(page);
                }                
            }

            report.ExportDocument(StiExportFormat.Pdf, "d:\\1.pdf");
Thank you.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

"Insufficient memory" during merging reports

Post by Fabio Pagano »

I haven't tried the code yet, but i think that this line:

Code: Select all

page.Report = tempReport;
should be:

Code: Select all

page.Report = report;
Please, let me know the correct one.

Thank you.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

"Insufficient memory" during merging reports

Post by Fabio Pagano »

Don't consider previous post, i think i have found a problem now.

I have tried your code.

If i use about 40 reports, in the pdf file i see duplicated reports.

Please, try your code with different reports (almost 40) and you should see that behavior.

Your code works (or seems to work) because the report that you load is always the same.

If needed, i can give my 40 .mdz files that i have used to test your code.

Thank you.
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

"Insufficient memory" during merging reports

Post by Ivan »

Hello,

Here is another sample code which provide functionality for export many reports into one big pdf file.

Code: Select all

            string pthOk = Application.StartupPath + "\\fatt";
            DirectoryInfo di = new DirectoryInfo(pthOk);
            FileInfo[] strs = di.GetFiles();

            StiReport newreport = new StiReport();
            newreport.ReportCacheMode = StiReportCacheMode.On;
            newreport.RenderedPages.CanUseCacheMode = true;
            newreport.RenderedPages.CacheMode = true;
            newreport.RenderedPages.Clear();

            foreach(FileInfo fi in strs)
            {
                StiReport rep = new StiReport();
                rep.LoadDocument(fi.FullName);
                rep.ReportUnit = newreport.ReportUnit;

                foreach (StiPage repPage in rep.RenderedPages)
                {
                  repPage.Report = newreport;
                  repPage.Guid = System.Guid.NewGuid().ToString().Replace("-", "");
                  newreport.RenderedPages.Add(repPage);
                }
            }

            newreport.ExportDocument(StiExportFormat.Pdf, "d:\\extraPages.pdf");
Thank you.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

"Insufficient memory" during merging reports

Post by Fabio Pagano »

It has worked, thank you very much. I'd like to know if the "guid trick" is a temporary workaround or a definitive solution.

I've noticed that exporting in pdf from the cumulative report, it needs 10 minutes from a report of 5788 pages (the generated pdf is 22 MB).

In previous tests, where i didn't use cache, it seemed to me that the pdf exporting time was much less, two minutes for exporting about 3500 pages. Of course i need to use cache, so i'll use it, but i'm just signaling this "slow pdf exporting" behavior when i use cache.

Thank you.
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

"Insufficient memory" during merging reports

Post by Ivan »

Hello,
Fabio wrote:It has worked, thank you very much. I'd like to know if the "guid trick" is a temporary workaround or a definitive solution.
It's a definitive solution.
Fabio wrote:I've noticed that exporting in pdf from the cumulative report, it needs 10 minutes from a report of 5788 pages (the generated pdf is 22 MB).
In previous tests, where i didn't use cache, it seemed to me that the pdf exporting time was much less, two minutes for exporting about 3500 pages. Of course i need to use cache, so i'll use it, but i'm just signaling this "slow pdf exporting" behavior when i use cache.
If ReportCachMode=On or Auto then rendered pages are stored in the disk cache, each page in the separate file.
When exporting, rendered pages are read from the cache (if required).
Speed of the disk is much smaller than the memory speed.
Therefore the speed of exports in this mode is slower.

Thank you.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

"Insufficient memory" during merging reports

Post by Fabio Pagano »

I've noticed that the ".mch" cache files are created in the application folder. Shouldn't they be created in user's temporary folder?
Post Reply