This project has moved. For the latest updates, please go here.

Memory is not released back

Sep 27, 2012 at 2:57 PM

Hi,

Watching the Task Manager, I noticed that in a process of creating a pretty large Excel file (~1.5 MB) on IIS, a lot more memory (~200MB) is added to IIS Worker Process (w3wp.exe). The memory count does not go down after a download is completed. Every new download increases that memory (not linearly, it reaches about 500MB and increases become smaller, but increases nevertheless). I use pretty much the same code as this one: http://epplus.codeplex.com/wikipage?title=WebapplicationExample. I also tried "try-catch-finally" block instead of "using" statement so I can call "Dispose" method directly, that did not help.

I do not want to reinvent the bicycle and use OpenXML directly. EPPLus has everything I need. Except this little problem, of course. I have also seen a few "out-of-memory" threads and none of them seems to be resolved. I wonder if you recognize this problem and plan to fix it in any future releases?

Thanks,

Yuri 

 

 

 

 

Oct 3, 2012 at 9:18 AM

Hi,

I also have the same problem as Yuri. Somethimes I need to create files of 3 - 5mb and the w3wp.exe rises until 1GB

Could someone please tell us, how to release the memory?

Thanks,
Jan 

Nov 28, 2012 at 3:53 PM

ExcelRangeBase has an eventhandler and the code to remove is is in the finalizer. But as the eventhandler holds a reference to the ExcelRangeBase instance, the finaliser will never be called.  Make sure that Dispose() is called on any references to ExcelRangeBase  when you've finished with them.  I don't know if this problem exists in any other classes, it probably will be an issue for ExcelRange and ExcelNamedRange as they inherit from ExcelRangeBase.

Mar 14, 2013 at 9:49 AM
I am facing the same issue and I used ANTS profiler. It showed that ExcelCell object is not garbage collected. But I could not figure out which object is holding reference of ExcelCell object. After this I decided to call GC.Collect(). I know its not advisable but GC.Collect() is doing the trick for me. I hope it will work in your case as well.
Mar 19, 2013 at 8:01 PM
So when I do something like
ExcelRange rng = sht.Cells[StartRow, col];
// use the rng reference to do stuff
You're saying I need to call rng.Dispose()?

If so, that's gonna be a serious maintenance issue...
Apr 5, 2013 at 12:37 AM
Hey,

I'm having this very same issue and It's impacting our systems significently since we consistently generate Excel files in the 10-30MB range. I have created a sample application for me to profile the code and I have tracked down all the ExcelCell objects and found that they are being held by RangeCollection. I have also modified/extended the dispose() method to dispose the Range collections from the ExcelWorksheet class and it releases all of the ExcelCell and RangCollection.IndexItem objects.

This patch does not solve the memory leak completely as there are still a bunch of objects being held but it does free up +95% of the objects in my test application. I would like to create a patch for this but I have not found where I can check out the code in some version control system so that I can easily do this. Any help?
Apr 15, 2013 at 9:14 AM
Hi,

I am also having the same issue, have anyone found a solution?
Jul 8, 2013 at 4:50 AM
Hello,

I am also facing this issue.
This is a very Critical issue for me.
Does anyone can share a Solution ?
Jul 24, 2013 at 10:50 AM
Same problem...

I tried everything... disposing, using a "using"... does anyone found a solution?
Jul 30, 2013 at 5:13 PM
Likewise here...it's currently preventing me from using EPPlus in production.
Jul 31, 2013 at 9:23 PM
Hey guys,

Sorry, I should have written you back on this. I have written a patch and committed it to the CleanupMemory branch in the source control. Please go ahead and download if from there.

It does a pretty good job of releasing the memory for the most part but there's still some memory not being cleaned up.

Thank you,


Steve.
Aug 1, 2013 at 6:37 AM
s_schwenker wrote:
Hey guys,

Sorry, I should have written you back on this. I have written a patch and committed it to the CleanupMemory branch in the source control. Please go ahead and download if from there.

It does a pretty good job of releasing the memory for the most part but there's still some memory not being cleaned up.

Thank you,


Steve.
Hi,

I have tried to debug your changes into dll and replace it back and run with calling excel package dispose, but still the memory keep increasing without release? Any advice?
Sep 13, 2013 at 2:20 PM
Maybe your use case is different than mine. I ended up creating a small program with my use case that caused the memory leak. I then debugged that.

Is it possible for you to write a small console app that reproduces your memory leak and send it to me?

Steve.
Sep 17, 2013 at 6:15 AM
Hi,

Thanks for your kind attention on the issue. I have temporarily solved the problem by splitting data into multiple Excel files, each limit to max 100K records, 1 sheet.
Anyway, I'll write the console app when I'm free again.

Thanks,
Hon Wai


Mar 13, 2014 at 6:59 PM
Where is the CleanupMemory branch you're referring to? Can't find it under the "Source Code" link.