unmanaged memory lead during printing

Stimulsoft Reports.NET discussion
Post Reply
benx
Posts: 2
Joined: Tue Oct 15, 2013 11:00 am

unmanaged memory lead during printing

Post by benx »

In our application server we create printjobs by calling renderedReport.SaveDocumentToByteArray(). Later we print these jobs in another process. The problem is, that some reports (bytearray and mrt are included) especially with background images permanently increase the memory usage of the print process. I have included a simple one page example that increases the memory footprint for about 120MB. With memory profiler we found that this leak is not managed but unmanaged memory.

Version: 2013.2.1700; .NET 4.5
i have uploaded the bytearray-bin-File an the original mrt-File

Code: Select all

[Test] 
public void StimulMemoryBug() {
    var saveDocumentToByteArray = File.ReadAllBytes(@"testdata\reportprint\serialized.bin"); // created with renderedReport.SaveDocumentToByteArray();
    var defaultprinter = PrinterSettings.InstalledPrinters.Cast<string>()
                     .Select(s => new PrinterSettings { PrinterName = s })
                     .First(t => t.IsDefaultPrinter);
    Console.Out.WriteLine(Process.GetCurrentProcess().PrivateMemorySize64); // Output is 24.088.576 
    using (var report = new StiReport()) {
        report.LoadDocument(saveDocumentToByteArray);
        report.Print(false, defaultprinter);
    }
    Console.Out.WriteLine(Process.GetCurrentProcess().PrivateMemorySize64); //120MB! Difference  Output is 146.366.464

}
Attachments
reportprint.zip
(3.68 MiB) Downloaded 110 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: unmanaged memory lead during printing

Post by HighAley »

Hello.

You are using image as a watermark of the page.
.Net Framework stores images in memory as unpacked bitmap.
It needs a lot of memory. So you get such memory footprint.

The GarbageCollector should manage the allocation and release of memory but you should forces an immediate garbage collection with GC.Cllect() method.
We are using next code to free memory:

Code: Select all

GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Thank you.
benx
Posts: 2
Joined: Tue Oct 15, 2013 11:00 am

Re: unmanaged memory lead during printing

Post by benx »

Worked for me, Thanks
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: unmanaged memory lead during printing

Post by HighAley »

Hello.

We are always glad to help you.
Let us know if you need any additional help.

Thank you.
Post Reply