Click here to Skip to main content
14,486,138 members
Rate this:
Please Sign up or sign in to vote.
See more:
Dear All,

My C# Windows Application uses microsoft report (rdlc).
I found high memory usage while running report.
Later I came to know that microsoft report has memory leak issue.
I uses .Net 4.0 and Visual Studio 2010.

Is there any solution or fix for this issue ?

Its very urgent ! ! !
Posted
Updated 18-Apr-19 15:52pm
Comments
   
How do you know it's a leak. If this is from Windows Task Manager, don't trust it.
—SA
Stanly Simon Trivandrum 14-Aug-13 3:09am
   
I found this using CLR Profiler
Stanly Simon Trivandrum 14-Aug-13 3:09am
   
also using dotTrace
Rate this:
Please Sign up or sign in to vote.

Solution 3

I was having the same issue with .NET 4.5 VS 2013

I tried several things, but what finally made it work was:

Compiling the project in x64 and using LocalReport.ReleaseSandBoxAppDomain()

I got part of the solution from here: http://stackoverflow.com/questions/6220915/very-high-memory-usage-in-net-4-0/34184809#34184809[^]
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 4

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.

Hope this helps!
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

   
v3
Rate this:
Please Sign up or sign in to vote.

Solution 2

   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100