Page 1 of 1

unmanaged memory lead during printing

Posted: Tue Oct 15, 2013 11:42 am
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

}

Re: unmanaged memory lead during printing

Posted: Thu Oct 17, 2013 5:54 am
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.

Re: unmanaged memory lead during printing

Posted: Wed Oct 23, 2013 4:10 pm
by benx
Worked for me, Thanks

Re: unmanaged memory lead during printing

Posted: Thu Oct 24, 2013 10:27 am
by HighAley
Hello.

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

Thank you.