AnsweredAssumed Answered

Memory leak with FeatureClass object

Question asked by joelautotte on Jan 14, 2013
Latest reply on Jan 15, 2013 by joelautotte
Hello ESRI developer community,

I've been working with the ESRI ArcObjects for many years now, mainly on an ETL (Extract/Transform/Load) .NET application.  This application can run for a long time to transfer data from an ESRI Geodatabase to the target system (for example, 3 consecutive days). 

We recently had a situation where our application crashes with an "OutOfMemory" exception.  To find the memory leak, we profiled our application with SciTech .NET Memory Profiler.  Since ArcObjects is a COM based library and that the application profiler can't give the detail about the instanciated objects, I had to comment the code of our application to narrow the possibilities of the objects used/function calls that was causing this memory leak. 

I ended up isolating the IFeatureWorkspace.OpenFeatureClass function being the main source of the problem.  This function is called multiple times during the 2-3 days of process and it seems like the FeatureClass object returned is never released. 

I read multiple articles about memory leak with ArcObjects and tried everything that was suggested to release the FeatureClass object, i.e.:


The .NET functions:

Marshal.ReleaseComObject
Marshal.FinalReleaseComObject


The ArcObject ComReleaser object with the following logic:

Using comReleaser As New ComReleaser()
    esriFeatureClass = _featureWorkspace.OpenFeatureClass(featureClassName)
    comReleaser.ManageLifetime(esriFeatureClass)
End Using


All this combined with the .NET Garbage Collector functions:

GC.Collect
GC.WaitForPendingFinalizers


I did a small application that simulates the same routine that our ETL application does to help for the profiling and also validate that the behavior is the same.  It turns out it has the same behavior, the amount of memory allocated is similar.  With the routine of opening the feature class repeated 450 times, there is 15 Mb that stays allocated at the end (SciTech Memory Profiler screenshot attached).  So when the process runs for 3 days, there is more than 200 Mb that stays allocated just for those FeatureClass alone. 

I attached the Visual Studio 2010 project that does the routine, so if you want to take a look at the code to see if i'm missing something.  Right now, I'm out of solution to fix that.  Any help would be greatly appreciated. 

I'm working with ESRI ArcGIS 9.3 (9.3.0.1770 is the version number of the ESRI DLLs in Visual Studio)

Thanks in advance,


Joel

Outcomes