Click here to Skip to main content
15,888,116 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have generated an rdlc report with about 50 parameters. I have exported this report to image dynamically through localreport.render method. System.outofmemory exception occurs when the report is frequently exported. Plz Help.
Posted
Updated 18-Apr-19 16:08pm
v4
Comments
kiquenet.com 30-Oct-15 12:43pm    
My case about ***OutOfMemoryException*** not memory problem, I don't know yet http://stackoverflow.com/questions/33436607/outofmemoryexception-using-rdlc-localreport-microsoft-reporting-webforms-in-as# _Maybe configuration IIS, Pool, web.config issues ?_

I'm pretty late to this, but I have a real solution and can explain why!

It turns out that LocalReport here is using .NET Remoting to dynamically create a sub appdomain and run the report in order to avoid a leak internally somewhere. We then notice that, eventually, the report will release all the memory after 10 to 20 minutes. For people with a lot of PDFs being generated, this isn't going to work. However, the key here is that they are using .NET Remoting. One of the key parts to Remoting is something called "Leasing". Leasing means that it will keep that Marshal Object around for a while since Remoting is usually expensive to setup and its probably going to be used more than once. LocalReport RDLC is abusing this.

By default, the leasing time is... 10 minutes! Also, if something makes various calls into it, it adds another 2 minutes to the wait time! Thus, it can randomly be between 10 and 20 minutes depending how the calls line up. Luckily, you can change how long this timeout happens. Unluckily, you can only set this once per app domain... Thus, if you need remoting other than PDF generation, you will probably need to make another service running it so you can change the defaults. To do this, all you need to do is run these 4 lines of code at startup:

    LifetimeServices.LeaseTime = TimeSpan.FromSeconds(5);
    LifetimeServices.LeaseManagerPollTime = TimeSpan.FromSeconds(5);
    LifetimeServices.RenewOnCallTime = TimeSpan.FromSeconds(1);
    LifetimeServices.SponsorshipTimeout = TimeSpan.FromSeconds(5);

You'll see the memory use start to rise and then within a few seconds you should see the memory start coming back down. Took me days with a memory profiler to really track this down and realize what was happening.

You can't wrap ReportViewer in a using statement (Dispose crashes), but you should be able to if you use LocalReport directly. After that disposes, you can call GC.Collect() if you want to be doubly sure you are doing everything you can to free up that memory.

Hope this helps!
 
Share this answer
 
AFAIK, there is not much(code wise) that you can do about it.
Refer the following support article: MS Support: You may receive the "System.OutOfMemoryException" error message when you use SQL Server Reporting Services[^]

Look at this discussion on similar lines: Export To Excel Error throws System.OutOfMemoryException[^]

Try to upgrade your web server - look at the RAM available on the server, the processor utilization when the report is called, and the amount of server disk space (for temp storage).
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900