This is a migrated thread and some comments may be shown as answers.

LOH Memory Fragmentation

3 Answers 99 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 07 Oct 2011, 06:30 AM
I have a multi-threaded application creating PDF reports where some reports have 4000+ images per report.  The final report size can be a few megabytes.  What I believe I'm observing to-date is LOH memory fragmentation due to the local memory allocation of the ReportResult object.   I've just started looking at this issue and whether or not I can pin some memory.

Any suggestions to reduce LOH memory fragmentation when rendering PDF report files?

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 11 Oct 2011, 05:34 PM
Hello Tom,

In the latest release of Telerik Reporting we have introduced a dedicated Session State Management system to store and cache rendered pages and some large resources such as images on an external storage. This new way of resources handling should handle the LOH memory fragmentation issues. Thus our suggestions is to upgrade to the latest release of Telerik Reporting Q2 2011 Service Pack 1.

Best wishes,
Peter
the Telerik team

Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

0
Tom
Top achievements
Rank 1
answered on 20 Oct 2011, 07:34 PM
The documentation indicates this is for report viewers only.  I am only calling ReportProcessor.RenderReport() and getting back byte[] in the result.  Since the setter for byte[] DocumentBytes is internal, I cannot pre-allocate memory and reuse objects to avoid fragmentation for large reports rendering concurrently on several threads.  Gen 0 and Gen 2 heaps get huge and so does LOH.  I haven't gotten my head around this problem yet.  I'm about to test individual AppDomains since I can't seem to control the garbage collection of the reporting objects.  Any suggestions are welcome.
0
Peter
Telerik team
answered on 25 Oct 2011, 02:56 PM
Hello Tom,

Generally session state management in the processing stage offloads from the memory images larger than 84 kB.  Thus if the images are larger then 84 kB upgrading to Q2 SP1 will decrease the LOH fragmentation.

Additionally you can decrease the LOH fragmentation by utilizing the RenderReport overload that accepts CreateStream callback. This way you can avoid additional memory stream and instead use directly a filestream as shown in the following code snippet:

void RenderReport()
{
    var reportProcessor = new ReportProcessor();
    var documentName = "";
    var deviceInfo = new Hashtable();
    reportProcessor.RenderReport("PDF", new DashBoard(), deviceInfo, this.CreateStream, out documentName);
    this.CloseStreams();
}
 
void CloseStreams()
{
    foreach(var stream in this.streams)
    {
        stream.Close();
    }
    this.streams.Clear();
}
 
public Stream CreateStream(string name, string extension, Encoding encoding, string mimeType)
{
    const string path = @"C:\Reports\";
    var filePath = Path.Combine(path, name + "."+ extension);
    var fs = new FileStream(filePath, FileMode.Create);
    this.streams.Add(fs);
    return fs;
}
Kind regards,
Peter
the Telerik team

Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

Tags
General Discussions
Asked by
Tom
Top achievements
Rank 1
Answers by
Peter
Telerik team
Tom
Top achievements
Rank 1
Share this question
or