<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Memory leak with FeatureClass object in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584798#M15825</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Good luck with trying to open the featureclass once per run. Thats exactly what i'm doing and after a few runs my process crashes or gives me an "attempted to read or write protected memory" error that we traced down to the FeatureClass.Search() call.&amp;nbsp; Seems to me even between runs the featureclass is being held and some sort of memory buildup causes our crash. If you have better luck please let me know. Jason, from this post, has tried to help us with our problem too which is greatly appreciated.&lt;BR /&gt;&lt;BR /&gt;Gary&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Gary, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; yes I was suspicious about doing that... in the end, it didn't work.&amp;nbsp; When we use the same FeatureClass instance for the whole process, at some point, the process hangs at the function "FeatureClass.Search".&amp;nbsp; So no luck with this work-around...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Jan 2013 17:31:25 GMT</pubDate>
    <dc:creator>JoelAutotte</dc:creator>
    <dc:date>2013-01-18T17:31:25Z</dc:date>
    <item>
      <title>Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584782#M15809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello ESRI developer community, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; I've been working with the ESRI ArcObjects for many years now, mainly on an ETL (Extract/Transform/Load) .NET application.&amp;nbsp; This application can run for a long time to transfer data from an ESRI Geodatabase to the target system (for example, 3 consecutive days).&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; We recently had a situation where our application crashes with an "OutOfMemory" exception.&amp;nbsp; To find the memory leak, we profiled our application with SciTech .NET Memory Profiler.&amp;nbsp; 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.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; I ended up isolating the IFeatureWorkspace.OpenFeatureClass function being the main source of the problem.&amp;nbsp; This function is called multiple times during the 2-3 days of process and it seems like the FeatureClass object returned is never released.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; I read multiple articles about memory leak with ArcObjects and tried everything that was suggested to release the FeatureClass object, i.e.:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The .NET functions:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Marshal.ReleaseComObject&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Marshal.FinalReleaseComObject&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The ArcObject ComReleaser object with the following logic:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Using comReleaser As New ComReleaser()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; esriFeatureClass = _featureWorkspace.OpenFeatureClass(featureClassName)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; comReleaser.ManageLifetime(esriFeatureClass)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End Using&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All this combined with the .NET Garbage Collector functions:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;GC.Collect&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GC.WaitForPendingFinalizers&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&amp;nbsp; It turns out it has the same behavior, the amount of memory allocated is similar.&amp;nbsp; 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).&amp;nbsp; So when the process runs for 3 days, there is more than 200 Mb that stays allocated just for those FeatureClass alone.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&amp;nbsp; Right now, I'm out of solution to fix that.&amp;nbsp; Any help would be greatly appreciated.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm working with ESRI ArcGIS 9.3 (9.3.0.1770 is the version number of the ESRI DLLs in Visual Studio)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Joel&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Jan 2013 14:30:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584782#M15809</guid>
      <dc:creator>JoelAutotte</dc:creator>
      <dc:date>2013-01-14T14:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584783#M15810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: rlwatson&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One thing that you might be able to do is to try to work around the problem by giving ArcMap more memory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can do that by setting the large address aware bit on ArcMap.exe and then run your problem on a 64 bit operating system.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Normally, ArcMap gets 2 GB and the OS gets 2 GB of virtual memory.&amp;nbsp; If you do the above then the OS can move elsewhere leaving ArcMap with 4 GB of memory.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 00:35:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584783#M15810</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-01-15T00:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584784#M15811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Without seeing your code, it is hard to determine where or what the problem is. If you can post code, I will help you get the Marshal.ReleaseComObject calls correct (over-releasing is just as bad as under-releasing.) I would recommend never using Marshal.FinalReleaseComObject because it is more likely to cause you problems than not (see previous remark about over-releasing.) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[CORRECTION: I just noticed that an example is attached to your post. I will take a look.]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, I wouldn't manually call garbage collection using GC.Collect() and GC.WaitForPendingFinalizers()--if you release the RCWs correctly, they will detach from the COM objects which will going away immediately and the RCWs are small and will be cleaned up soon afterwards. The garbage collector will not collect unmanaged memory (COM objects), it only decrements the RCWs reference count as it becomes unrooted, and decrements the COM objects reference count once the RCW's reference count reaches 0. Finally, manually calling garbage collection can has serious performance implications.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can use UMDH to discover what calls (along with the rest of the call stack) were used to allocate the memory that isn't being freed. If you post the results of doing what I describe below, it will help us to help you discover the source of the problem you're having. It will also help to determine whether or not ArcObjects has a memory leak or if the problem is in your code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps. I'm looking forward to seeing your results (and possibly some code.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;INSTALLING THE NECESSARY TOOLS:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Download Debugging Tools for Windows. You will likely have to download the entire Windows SDK, but you can browse the ISO for the dbg_x86.msi and just install it. Make sure and install the x86 version regardless of your machine's architecture.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx"&gt;http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Add a &lt;/SPAN&gt;&lt;STRONG&gt;User &lt;/STRONG&gt;&lt;SPAN&gt;Environment Variable called _NT_SYMBOL_PATH and set its value to this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;cache*C:\dev\symbols;SRV*C:\dev\symbols*http://msdl.microsoft.com/download/symbols;SRV*C:\dev\symbols*http://downloads2.esri.com/Support/symbols/&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will allow you to resolve the debugging symbols you need.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Add a &lt;/SPAN&gt;&lt;STRONG&gt;System &lt;/STRONG&gt;&lt;SPAN&gt;Environment variable called OANOCACHE and set its value to 1. The disables Ole Automation caching, which is necessary to get accurate information about which calls allocated memory. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;4. [OPTIONAL] Add the Debugging Tools for Windows path to you &lt;/SPAN&gt;&lt;STRONG&gt;User &lt;/STRONG&gt;&lt;SPAN&gt;Environment Variables (C:\Program Files (x86)\Debugging Tools for Windows (x86)\ for x64 machines, C:\Program Files\Debugging Tools for Windows (x86)\ for x86 machines)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;USING UMDH TO ANALYZE PROBLEM:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;5. Use gflags to turn stack tracing on:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gflags -i arcmap.exe +ust&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are running a standalone application that uses ArcObjects, replace arcmap.exe with the name of your executable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;6. Start your application.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;7. Mark memory before executing the code you suspect is leaking memory by running UMDH:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; umdh -pn:arcmap.exe -f:mark1.txt&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;8. Execute the code that you suspect is leaking memory and the code that you think should release memory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;9. Mark memory again after step 8 is complete:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; umdh -pn:arcmap.exe -f:mark2.txt&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;10. Create a diff file for the two marks:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; umdh -d mark1.txt mark2.txt -f:results.txt&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The -d switch just outputs in decimal format rather than hexadecimal and makes it easier to read.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;11. Open the text file to find something like the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;&lt;BR /&gt;&amp;lt;Lots of information about the symbol files that were loaded?&lt;BR /&gt;...&lt;BR /&gt;&amp;lt;Stacks for allocated memory in order from highest consumption to lowest consumption&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;+ 1520000 ( 1520000 - 0) 10000 allocs BackTrace106BF720&lt;BR /&gt;+ 10000 ( 10000 - 0) BackTrace106BF720 allocations&lt;BR /&gt;&lt;BR /&gt;ntdll!RtlAllocateHeap+00000274&lt;BR /&gt;MSVCR90!malloc+00000079&lt;BR /&gt;MSVCR90!operator new+0000001F&lt;BR /&gt;Geometry!ESRI::Point::Clone+0000000D&lt;BR /&gt;EngineGraphics!GraphicTracker::AddWithOptions+0000004D&lt;BR /&gt;EngineGraphics!GraphicTracker::Add+00000051&lt;BR /&gt;mscorwks!CLRToCOMWorker+0000019A&lt;BR /&gt;&amp;lt;no module&amp;gt;!???+00000000 : 3CA70A&lt;BR /&gt;&lt;BR /&gt;+ 1520000 ( 1520000 - 0) 10000 allocs BackTraceB522378&lt;BR /&gt;+ 10000 ( 10000 - 0) BackTraceB522378 allocations&lt;BR /&gt;&lt;BR /&gt;ntdll!RtlAllocateHeap+00000274&lt;BR /&gt;MSVCR90!malloc+00000079&lt;BR /&gt;MSVCR90!operator new+0000001F&lt;BR /&gt;Geometry!ESRI::Point::Clone+0000000D&lt;BR /&gt;EngineGraphics!GraphicTracker::GetGT+00000087&lt;BR /&gt;EngineGraphics!GraphicTracker::AddReplaceGeometryToDraw+00000102&lt;BR /&gt;EngineGraphics!GraphicTracker::AddWithOptions+0000019A&lt;BR /&gt;EngineGraphics!GraphicTracker::Add+00000051&lt;BR /&gt;mscorwks!CLRToCOMWorker+0000019A&lt;BR /&gt;&amp;lt;no module&amp;gt;!???+00000000 : 3CA70A&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;CLEANUP AFTER YOU'RE DONE ANALYZING:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do the following to make sure you machine performance is optimal when you aren't debugging:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;12. Use the following to turn off stack tracing when you are finished.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gflags -i arcmap.exe -ust&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;13. Set OANOCACHE to 0.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 13:00:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584784#M15811</guid>
      <dc:creator>JasonPike</dc:creator>
      <dc:date>2013-01-15T13:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584785#M15812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: ScJpike&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello ESRI developer community, &lt;BR /&gt;&lt;BR /&gt; I've been working with the ESRI ArcObjects for many years now, mainly on an ETL (Extract/Transform/Load) .NET application.&amp;nbsp; This application can run for a long time to transfer data from an ESRI Geodatabase to the target system (for example, 3 consecutive days).&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt; We recently had a situation where our application crashes with an "OutOfMemory" exception.&amp;nbsp; To find the memory leak, we profiled our application with SciTech .NET Memory Profiler.&amp;nbsp; 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.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt; I ended up isolating the IFeatureWorkspace.OpenFeatureClass function being the main source of the problem.&amp;nbsp; This function is called multiple times during the 2-3 days of process and it seems like the FeatureClass object returned is never released.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt; I read multiple articles about memory leak with ArcObjects and tried everything that was suggested to release the FeatureClass object, i.e.:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The .NET functions:&lt;BR /&gt;&lt;BR /&gt;Marshal.ReleaseComObject&lt;BR /&gt;Marshal.FinalReleaseComObject&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The ArcObject ComReleaser object with the following logic:&lt;BR /&gt;&lt;BR /&gt;Using comReleaser As New ComReleaser()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; esriFeatureClass = _featureWorkspace.OpenFeatureClass(featureClassName)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; comReleaser.ManageLifetime(esriFeatureClass)&lt;BR /&gt;End Using&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;All this combined with the .NET Garbage Collector functions:&lt;BR /&gt;&lt;BR /&gt;GC.Collect&lt;BR /&gt;GC.WaitForPendingFinalizers&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;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.&amp;nbsp; It turns out it has the same behavior, the amount of memory allocated is similar.&amp;nbsp; 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).&amp;nbsp; So when the process runs for 3 days, there is more than 200 Mb that stays allocated just for those FeatureClass alone.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;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.&amp;nbsp; Right now, I'm out of solution to fix that.&amp;nbsp; Any help would be greatly appreciated.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;I'm working with ESRI ArcGIS 9.3 (9.3.0.1770 is the version number of the ESRI DLLs in Visual Studio)&lt;BR /&gt;&lt;BR /&gt;Thanks in advance, &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Joel&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would avoid using Esri's ComReleaser object--it is only useful in very specific situations and will cause problems in every other situation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using version 10.1 and haven't tested this code. I might spend some more time on it when I get home this evening. Let me know if the modifications below improve your results.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Imports ESRI.ArcGIS.ADF
Imports ESRI.ArcGIS.DataSourcesFile
Imports ESRI.ArcGIS.DataSourcesGDB
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS
Imports System.Runtime.InteropServices

Public Class Form1

&amp;nbsp;&amp;nbsp;&amp;nbsp; Private _featureClassNames As List(Of String)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Private _featureWorkspace As IFeatureWorkspace

&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Sub InitializeFeatureClassNames()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _featureClassNames = New List(Of String)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _featureClassNames.Add("ARCFM.Airport")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _featureClassNames.Add("ARCFM.Bridge")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _featureClassNames.Add("ARCFM.Building")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _featureClassNames.Add("etc...")
&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub

&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Sub ESRI_Connect()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim propSet As New ESRI.ArcGIS.esriSystem.PropertySet
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim wsFactory As Geodatabase.IWorkspaceFactory = Nothing

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Try
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wsFactory = New DataSourcesGDB.SdeWorkspaceFactory()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; propSet = New ESRI.ArcGIS.esriSystem.PropertySet()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; With propSet
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .SetProperty("SERVER", "put SDE server name here")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .SetProperty("INSTANCE", "put SDE service port here")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .SetProperty("DATABASE", "put Oracle database service name here")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .SetProperty("USER", "put Oracle user name here")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .SetProperty("PASSWORD", "put Oracle user password here")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .SetProperty("VERSION", "SDE.DEFAULT")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End With

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Try to access the ESRI source data
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _featureWorkspace = wsFactory.Open(propSet, 0)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Finally
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If propSet IsNot Nothing Then Marshal.ReleaseComObject(propSet)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If wsFactory IsNot Nothing Then Marshal.ReleaseComObject(wsFactory)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Try
&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub

&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' &amp;lt;summary&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' This is the main loop where the Workspace.OpenFeatureClass function is called.&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' &amp;lt;/summary&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' &amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Sub LoopOpenFeatureClasses()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; For Each featureClassName As String In _featureClassNames
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim esriFeatureClass As Geodatabase.IFeatureClass = Nothing

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Try
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; esriFeatureClass = _featureWorkspace.OpenFeatureClass(featureClassName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Catch ex As Exception
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Finally
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If esriFeatureClass IsNot Nothing Then Marshal.ReleaseComObject(esriFeatureClass)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Try
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next
&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub

&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' &amp;lt;summary&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' Initializes the application to use the ArcObjects libraries.&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' &amp;lt;/summary&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' &amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Sub InitializeArcObjects()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim aoInitialize = New AoInitialize()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim licenseStatus As esriLicenseStatus = aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcView)
&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub

&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Try
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeFeatureClassNames()

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeArcObjects()

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' initializes _featureWorkspace
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ESRI_Connect()

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; For i As Integer = 1 To 450
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LoopOpenFeatureClasses()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Catch ex As Exception
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Finally
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If _featureWorkspace IsNot Nothing Then Marshal.ReleaseComObject(_featureWorkspace)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Try

&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub

End Class&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:08:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584785#M15812</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T01:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584786#M15813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: joelautotte&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;One thing that you might be able to do is to try to work around the problem by giving ArcMap more memory.&lt;BR /&gt;&lt;BR /&gt;You can do that by setting the large address aware bit on ArcMap.exe and then run your problem on a 64 bit operating system.&lt;BR /&gt;&lt;BR /&gt;Normally, ArcMap gets 2 GB and the OS gets 2 GB of virtual memory.&amp;nbsp; If you do the above then the OS can move elsewhere leaving ArcMap with 4 GB of memory.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your reply.&amp;nbsp; Unfortunately, we don't have the control on the OS used since our application is installed in the environment of many of our customers.&amp;nbsp; Also, it doesn't run in ArcMap, it's a standalone .NET application.&amp;nbsp; If it wasn't leaking, our application is not that memory intensive.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 19:08:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584786#M15813</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-01-15T19:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584787#M15814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your help, Jason.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; I followed the procedure with the Windows Debugging Tools.&amp;nbsp; To give you an idea of my test, here is the loop that i executed right after I start marking the memory: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For i As Integer = 1 To 5&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'There is about 21 feature classes in that "_featureClassNames" collection &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For Each featureClassName As String In _featureClassNames&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]Dim esriFeatureClass As Geodatabase.IFeatureClass = Nothing&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;esriFeatureClass = _featureWorkspace.OpenFeatureClass(featureClassName)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Marshal.ReleaseComObject(esriFeatureClass)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/INDENT]Next&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/INDENT]Next&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then took the second mark after and did the difference.&amp;nbsp; I attached the result file to the thread (results.txt).&amp;nbsp; I did a research with the "ESRI" keyword in the text file and i can find a couple of places where we can see the trace of the memory allocated.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So do you think there is something wrong in my code?&amp;nbsp; Or that the ESRI objects are not released and that I don't have any control on this?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again, very appreciated!&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Joel&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 19:27:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584787#M15814</guid>
      <dc:creator>JoelAutotte</dc:creator>
      <dc:date>2013-01-15T19:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584788#M15815</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think that the "results.txt" file didn't make it in my previous post because it was too big.&amp;nbsp; Here it is, compressed.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 19:31:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584788#M15815</guid>
      <dc:creator>JoelAutotte</dc:creator>
      <dc:date>2013-01-15T19:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584789#M15816</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: kirkktx&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've never noticed problems with using "new" with workspacefactories ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;wsFactory = New DataSourcesGDB.SdeWorkspaceFactory()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However,&lt;/SPAN&gt;&lt;A href="http://resources.esri.com/help/9.3/arcgisengine/dotnet/fde31db0-af15-409f-81b5-75c23d4a762e.htm" rel="nofollow noopener noreferrer" target="_blank"&gt; Esri recommends&lt;/A&gt;&lt;SPAN&gt; using Activator to create new instances:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory")
Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:08:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584789#M15816</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T01:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584790#M15817</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thank you for your help, Jason.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; I followed the procedure with the Windows Debugging Tools.&amp;nbsp; To give you an idea of my test, here is the loop that i executed right after I start marking the memory: &lt;BR /&gt;&lt;BR /&gt;For i As Integer = 1 To 5&lt;BR /&gt;[INDENT]&lt;BR /&gt;'There is about 21 feature classes in that "_featureClassNames" collection &lt;BR /&gt;For Each featureClassName As String In _featureClassNames&lt;BR /&gt;&lt;BR /&gt;[INDENT]Dim esriFeatureClass As Geodatabase.IFeatureClass = Nothing&lt;BR /&gt;&lt;BR /&gt;esriFeatureClass = _featureWorkspace.OpenFeatureClass(featureClassName)&lt;BR /&gt;Marshal.ReleaseComObject(esriFeatureClass)&lt;BR /&gt;[/INDENT]Next&lt;BR /&gt;[/INDENT]Next&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Then took the second mark after and did the difference.&amp;nbsp; I attached the result file to the thread (results.txt).&amp;nbsp; I did a research with the "ESRI" keyword in the text file and i can find a couple of places where we can see the trace of the memory allocated.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;So do you think there is something wrong in my code?&amp;nbsp; Or that the ESRI objects are not released and that I don't have any control on this?&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks again, very appreciated!&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Joel&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Joel,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The results you posted look pretty good actually. I don't see any leaks as a result of the OpenFeatureClass call. In fact, if you do a search on "OpenFeatureClass" in the document, it returns nothing, which is a good indicator that it isn't responsible for whatever UMDH caught. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Did your test code show the same problem that your production code is showing? If not, then I think that the problem may be on your side. If the test code does show the same problem, but UMDH didn't turn anything up, you may need to look at other sections of code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You should also try what Kirk suggested. I think he doesn't expect any difference (nor do I), but it never hurts to try.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'll let you know if I have time to construct an example using my own data that will reproduce the problem. Please keep posting your progress on the board.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jason&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 20:20:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584790#M15817</guid>
      <dc:creator>JasonPike</dc:creator>
      <dc:date>2013-01-15T20:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584791#M15818</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: kenbuja&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jason,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could you expand a little on your statement &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I would avoid using Esri's ComReleaser object--it is only useful in very&amp;nbsp; specific situations and will cause problems in every other situation.&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 20:29:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584791#M15818</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-01-15T20:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584792#M15819</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Jason,&lt;BR /&gt;&lt;BR /&gt;Could you expand a little on your statement&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd be happy to explain. Perhaps I'll eventually provide code examples, but it could be a while before I have time. Until then, here is the short story:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;COM objects do not reside in managed memory; they reside on the unmanaged heap. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;COM objects are used in .NET through proxies called Runtime Callable Wrappers (RCWs) that reside on the managed heap.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;COM objects use reference counting to determine when they can be deallocated. They maintain a count of references to themselves and deallocate when that counter reaches 0. When a reference to a COM object is made in .NET, a RCW is created an the COM object is incremented once and only once for that instance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;RCWs also maintain a reference count. It is separate from the underlying COM object's reference count; it tracks the number of times IUnknown is marshalled from the unmanaged heap to the managed heap. When the RCW's reference count reaches zero, it detachs itself from the COM object which causes the COM object's reference to decrement by 1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The most important thing to remember is that for an instance of an object (e.g. a layer object containing rivers, a feature class object containing cities, etc.) there is only one, shared RCW per application domain. If that RCW is detached from the COM object, then it is detached for every managed (read: .NET) object in that application domain, including .NET code that you didn't write and have no control over. Unless you've created your own application domain, every COM object you reference in your managed code will be loaded into the Shared application domain (1 of 3 application domains created by default for each .NET process) and shared with the rest of the managed code in the process. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Microsoft provides two methods for manually releasing COM objects for cases where deterministic memory management is required and the non-deterministic .NET garbage collector cannot be relied upon:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]Marshal.ReleaseComObject - decrements the RCW's reference count by 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Marshal.FinalReleaseComObject - decrements the RCW's reference count until it reaches zero and detaches the underlying COM object[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code should only ever call ReleaseComObject as many times as it has incremented the reference count. If the RCW is released too many times, it can detach the underlying COM object before other objects that reference it are finished with it. When this happens, you get the very familiar: "COM object that has been separated from its underlying RCW cannot be used." &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;FinalReleaseCom object should only be used when the caller is absolutely sure no other objects are referencing the COM object--this includes managed code in the application domain that you may not have created. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As noted in other threads, ComReleaser essentially calls Marshal.FinalReleaseComObject for every object you've told it to manage. This means that you had better be sure that no other managed code in the application domain (your product, other 3rd parties, etc.) is holding a reference to the RCWs you've told it to manage. Since you can't know what other managed code might be running in the process, I think that it is unsafe to use ComReleaser--instead, COM interop should be understood and applied carefully using ReleaseComObject appropriately. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I understand that COM interop is an advanced programming topic and that the ComReleaser class was meant to lessen the pain for developers that didn't want to take the time learn it. However, this is when ComReleaser is most dangerous--when it is used by developers who don't understand its limitations and ramifications. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've had bugs filed against products I've developed only to find out that they only occurred when another product was installed alongside it and which eventually led to the discovery that the other product had mismanaged RCWs that our product happened to be using also. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, all that to say: ComReleaser is useful if you are absolutely sure you're passing it objects that are not referenced anywhere else in the application domain; otherwise, you risk the stability of the program when you use it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Resources:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://www.amazon.com/NET-COM-Complete-Interoperability-Guide/dp/067232170X"&gt;http://www.amazon.com/NET-COM-Complete-Interoperability-Guide/dp/067232170X&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://www.amazon.com/Advanced-NET-Debugging-Mario-Hewardt/dp/0321578899"&gt;http://www.amazon.com/Advanced-NET-Debugging-Mario-Hewardt/dp/0321578899&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/2bh4z9hs(v=vs.110).aspx"&gt;http://msdn.microsoft.com/en-us/library/2bh4z9hs(v=vs.110).aspx&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://en.wikipedia.org/wiki/Reference_counting"&gt;http://en.wikipedia.org/wiki/Reference_counting&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/8bwh56xe.aspx"&gt;http://msdn.microsoft.com/en-us/library/8bwh56xe.aspx&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2013 01:47:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584792#M15819</guid>
      <dc:creator>JasonPike</dc:creator>
      <dc:date>2013-01-16T01:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584793#M15820</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: joelautotte&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Joel,&lt;BR /&gt;&lt;BR /&gt;The results you posted look pretty good actually. I don't see any leaks as a result of the OpenFeatureClass call. In fact, if you do a search on "OpenFeatureClass" in the document, it returns nothing, which is a good indicator that it isn't responsible for whatever UMDH caught. &lt;BR /&gt;&lt;BR /&gt;Did your test code show the same problem that your production code is showing? If not, then I think that the problem may be on your side. If the test code does show the same problem, but UMDH didn't turn anything up, you may need to look at other sections of code.&lt;BR /&gt;&lt;BR /&gt;You should also try what Kirk suggested. I think he doesn't expect any difference (nor do I), but it never hurts to try.&lt;BR /&gt;&lt;BR /&gt;I'll let you know if I have time to construct an example using my own data that will reproduce the problem. Please keep posting your progress on the board.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Jason&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jason, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I agree, the OpenFeatureClass is not logged in the result.&amp;nbsp; But, I would like be able to explain why the SciTech .NET Memory Profiler displays an increase of the "Unidentified unmanaged heaps" memory when this loop is performed.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; In the result.txt file, I see other call stack trace related to ESRI objects, some of them: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Related to Miner &amp;amp; Miner ArcFM:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; mmGeoObjects!???+00000000 : 27412D03&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; mmSystemObjects!DllGetClassObject+0000D4FB&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Others:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; Geometry!SpatialReferenceEnvironment::CreateESRISpatialReference+00000019&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; SdeFDB!SdeCursor::SetupGeometry+000000D9&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; sde!SES_stream_ok+00000B04&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; GdbCore!ClassHelper::Init+0000002B&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think it is fair to say that, since the scope of the memory marking is only for the "OpenFeatureClass" function, these functions end up being called when doing "OpenFeatureClass".&amp;nbsp; For some reasons, UMDH doesn't seem to be able to trace the function call stack back to "OpenFeatureClass" function... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for your help, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Joel&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2013 17:01:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584793#M15820</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-01-16T17:01:35Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584794#M15821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Jason, &lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I agree, the OpenFeatureClass is not logged in the result.&amp;nbsp; But, I would like be able to explain why the SciTech .NET Memory Profiler displays an increase of the "Unidentified unmanaged heaps" memory when this loop is performed.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; In the result.txt file, I see other call stack trace related to ESRI objects, some of them: &lt;BR /&gt;&lt;BR /&gt;Related to Miner &amp;amp; Miner ArcFM:&lt;BR /&gt;&lt;BR /&gt; mmGeoObjects!???+00000000 : 27412D03&lt;BR /&gt; mmSystemObjects!DllGetClassObject+0000D4FB&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Others:&lt;BR /&gt;&lt;BR /&gt; Geometry!SpatialReferenceEnvironment::CreateESRISpatialReference+00000019&lt;BR /&gt; SdeFDB!SdeCursor::SetupGeometry+000000D9&lt;BR /&gt; sde!SES_stream_ok+00000B04&lt;BR /&gt; GdbCore!ClassHelper::Init+0000002B&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I think it is fair to say that, since the scope of the memory marking is only for the "OpenFeatureClass" function, these functions end up being called when doing "OpenFeatureClass".&amp;nbsp; For some reasons, UMDH doesn't seem to be able to trace the function call stack back to "OpenFeatureClass" function... &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks again for your help, &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Joel&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;How much is memory usage increasing between iterations? Does it keep increasing each time if you run the workflow multiple times?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are a number of possibilities. Here are a few off the top of my head:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1) Some of the unmanaged memory could be the JIT-compiled code, which would only show up the first time you execute a method. Each method is compiled and the machine code cached in memory the first time a method is executed. The cached machine code stays in memory (unmanaged memory) until the process is torn down, if I remember correctly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2) Events may be fired when you open the feature class that cause other code to execute and allocate memory. If it is ArcFM, it will be harder to tell because I'm pretty sure they don't make their symbol files available. If you don't have symbol files, then you'll get something like this: mmGeoObjects!???+00000000 : 27412D03 that can show you the DLL, but not the class or method names. If there is a way to run your tests with ArcFM out of the picture, it should give you some idea as to whether ArcFM is contributing to your problem. If you know where to find ArcFM's symbol files or symbol server, please let me know--I could make use of them, too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3) UMDH doesn't just show leaks. It shows all the memory that was allocated between marks including things that ought not be released yet. You can limit the marks to only memory that is no longer referenced by using UMDH's -g flag when you mark memory. This may narrow your search some.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can also try the &lt;/SPAN&gt;&lt;A href="http://www.codeproject.com/Articles/108529/LeakDiag-An-Effective-Memory-Leak-Analysis-Tool"&gt;LeakDiag&lt;/A&gt;&lt;SPAN&gt; tool. I don't remember which heaps that UMDH monitors and doesn't monitor. There is a book called &lt;/SPAN&gt;&lt;A href="http://www.amazon.com/Advanced-Windows-Debugging-Mario-Hewardt/dp/0321374460"&gt;Advanced Windows Debugging&lt;/A&gt;&lt;SPAN&gt; that explains all of that. Unfortunately, I had to leave the copy I had with my previous employer since they bought it for me. I need to replace that because it is extremely useful in situations like this.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2013 21:01:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584794#M15821</guid>
      <dc:creator>JasonPike</dc:creator>
      <dc:date>2013-01-16T21:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584795#M15822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: joelautotte&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;How much is memory usage increasing between iterations? Does it keep increasing each time if you run the workflow multiple times?&lt;BR /&gt;&lt;BR /&gt;There are a number of possibilities. Here are a few off the top of my head:&lt;BR /&gt;&lt;BR /&gt;1) Some of the unmanaged memory could be the JIT-compiled code, which would only show up the first time you execute a method. Each method is compiled and the machine code cached in memory the first time a method is executed. The cached machine code stays in memory (unmanaged memory) until the process is torn down, if I remember correctly.&lt;BR /&gt;&lt;BR /&gt;2) Events may be fired when you open the feature class that cause other code to execute and allocate memory. If it is ArcFM, it will be harder to tell because I'm pretty sure they don't make their symbol files available. If you don't have symbol files, then you'll get something like this: mmGeoObjects!???+00000000 : 27412D03 that can show you the DLL, but not the class or method names. If there is a way to run your tests with ArcFM out of the picture, it should give you some idea as to whether ArcFM is contributing to your problem. If you know where to find ArcFM's symbol files or symbol server, please let me know--I could make use of them, too.&lt;BR /&gt;&lt;BR /&gt;3) UMDH doesn't just show leaks. It shows all the memory that was allocated between marks including things that ought not be released yet. You can limit the marks to only memory that is no longer referenced by using UMDH's -g flag when you mark memory. This may narrow your search some.&lt;BR /&gt;&lt;BR /&gt;You can also try the &lt;A href="http://www.codeproject.com/Articles/108529/LeakDiag-An-Effective-Memory-Leak-Analysis-Tool"&gt;LeakDiag&lt;/A&gt; tool. I don't remember which heaps that UMDH monitors and doesn't monitor. There is a book called &lt;A href="http://www.amazon.com/Advanced-Windows-Debugging-Mario-Hewardt/dp/0321374460"&gt;Advanced Windows Debugging&lt;/A&gt; that explains all of that. Unfortunately, I had to leave the copy I had with my previous employer since they bought it for me. I need to replace that because it is extremely useful in situations like this.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For 1 loop that opens the 21 feature classes, the memory increases of 40 Kb.&amp;nbsp; But it's not constant, it varies between 38 Kb and 47 Kb.&amp;nbsp; And it really keeps increasing steadily at every iteration.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I did a simple test yesterday.&amp;nbsp; To eliminate the COM wrappers from the equation, I did the same small application in Visual Basic 6.&amp;nbsp; Turns out I had the same behavior, the memory won't free even if I set the FeatureClass variable to "Nothing".&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm currently developing a work-around, I'll try to perform the OpenFeatureClass only once per feature class during the whole 2-3 days process.&amp;nbsp; At this point, I need to prove that calling OpenFeatureClass many times is the culprit in our process crash.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'll try to spend some time on the points 2) and 3) of your previous post.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a lot, you provided very helpful advice.&amp;nbsp; I'll give feedback about my work-around.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Joel&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jan 2013 18:03:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584795#M15822</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-01-17T18:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584796#M15823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;For 1 loop that opens the 21 feature classes, the memory increases of 40 Kb.&amp;nbsp; But it's not constant, it varies between 38 Kb and 47 Kb.&amp;nbsp; And it really keeps increasing steadily at every iteration.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;I did a simple test yesterday.&amp;nbsp; To eliminate the COM wrappers from the equation, I did the same small application in Visual Basic 6.&amp;nbsp; Turns out I had the same behavior, the memory won't free even if I set the FeatureClass variable to "Nothing".&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;I'm currently developing a work-around, I'll try to perform the OpenFeatureClass only once per feature class during the whole 2-3 days process.&amp;nbsp; At this point, I need to prove that calling OpenFeatureClass many times is the culprit in our process crash.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;I'll try to spend some time on the points 2) and 3) of your previous post.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks a lot, you provided very helpful advice.&amp;nbsp; I'll give feedback about my work-around.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Joel&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Great! I'm glad I was able to give you some new things to try. Definitely keep us informed about your progress and let us know if we can help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you get a chance, please vote up any of the posts that you found helpful.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jason&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jan 2013 19:18:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584796#M15823</guid>
      <dc:creator>JasonPike</dc:creator>
      <dc:date>2013-01-17T19:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584797#M15824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: gbushek&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;I'm currently developing a work-around, I'll try to perform the OpenFeatureClass only once per feature class during the whole 2-3 days process.&amp;nbsp; At this point, I need to prove that calling OpenFeatureClass many times is the culprit in our process crash.&amp;nbsp; &lt;BR /&gt;Joel&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck with trying to open the featureclass once per run. Thats exactly what i'm doing and after a few runs my process crashes or gives me an "attempted to read or write protected memory" error that we traced down to the FeatureClass.Search() call.&amp;nbsp; Seems to me even between runs the featureclass is being held and some sort of memory buildup causes our crash. If you have better luck please let me know. Jason, from this post, has tried to help us with our problem too which is greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Gary&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jan 2013 14:24:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584797#M15824</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-01-18T14:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584798#M15825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Good luck with trying to open the featureclass once per run. Thats exactly what i'm doing and after a few runs my process crashes or gives me an "attempted to read or write protected memory" error that we traced down to the FeatureClass.Search() call.&amp;nbsp; Seems to me even between runs the featureclass is being held and some sort of memory buildup causes our crash. If you have better luck please let me know. Jason, from this post, has tried to help us with our problem too which is greatly appreciated.&lt;BR /&gt;&lt;BR /&gt;Gary&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Gary, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; yes I was suspicious about doing that... in the end, it didn't work.&amp;nbsp; When we use the same FeatureClass instance for the whole process, at some point, the process hangs at the function "FeatureClass.Search".&amp;nbsp; So no luck with this work-around...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jan 2013 17:31:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584798#M15825</guid>
      <dc:creator>JoelAutotte</dc:creator>
      <dc:date>2013-01-18T17:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584799#M15826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: gbushek&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Gary, &lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; yes I was suspicious about doing that... in the end, it didn't work.&amp;nbsp; When we use the same FeatureClass instance for the whole process, at some point, the process hangs at the function "FeatureClass.Search".&amp;nbsp; So no luck with this work-around...&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;hmmm, identical problem as me. I guess when one of us figures it out we'll have solved the other's issue as well. We have a ticket in with ESRI on it so i'm hoping they can shed some light.&amp;nbsp; How big is the feature class you're tying to open that isn't being released?&amp;nbsp; Ours is roughly 20 million point features with 61 fields.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jan 2013 18:21:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584799#M15826</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-01-18T18:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584800#M15827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have either of you tried using WinDbg (it was installed alongside UMDH when you installed Debugging Tools for Windows) to get the stack when the exception (or freeze) occurs during the Search() call? If an exception is thrown, it should break and you can get the current stacks for all threads--I think ~*k will give you all the thread stacks. That could give you some idea of what is causing the Search() call to fail. If not, WinDbg is good for debugging applications that use both COM and .NET and you'll probably be able to use it in the future. If the application hangs, you can manually break in WinDbg and get the stacks to see where it is hung up. Also, if you're interested in using WinDbg for debugging things on the .NET side (it looks like you're both beyond that for this problem), you'll need to load SOS.dll (son of strike.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;WinDbg commands:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://windbg.info/doc/1-common-cmds.html"&gt;http://windbg.info/doc/1-common-cmds.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SOS commands:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb190764.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb190764.aspx&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please post your results to the forum.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, if this doesn't turn anything up, you can try Application Verifier. It can be difficult to get working with a product as large as ArcGIS, but if you can get a sample project to reproduce the problem using as little of ArcObjects as possible, you can probably get it going. Essentially, you tell it what image your interested in verifying (your stand-alone app that reproduces the problem) and configure it to test for what you want. Essentially, you want it to put guard pages around all your allocations so that it can help locate where and what the access violation was attempting to access. You'll need to use the heap verifier feature with full page heap enabled. After you get Application Verifier configured. Run your process with WinDbg attached and Application Verifier will break when something goes wrong in the heap. Depending on how strong the ArcObjects code is, you may hit a few things before you get to the problem you're looking for. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Application Verifier download:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://www.microsoft.com/en-us/download/details.aspx?id=20028"&gt;http://www.microsoft.com/en-us/download/details.aspx?id=20028&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;About guard pages and full page heap verification:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ms220938(v=vs.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/ms220938(v=vs.80).aspx&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jan 2013 12:45:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584800#M15827</guid>
      <dc:creator>JasonPike</dc:creator>
      <dc:date>2013-01-23T12:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak with FeatureClass object</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584801#M15828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: joelautotte&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Gary, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; it's been a while since I posted on this thread.&amp;nbsp; At a certain point, with all the different tests we did here, we concluded that the problem was definitely in the ArcObjects library and decided to move on.&amp;nbsp; But, in your last post, you mention that you already have a ticket number with ESRI for that problem.&amp;nbsp; It was just unclear if the ticket was for:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. the problem that you can't always call the OpenFeatureClass function in your routine since you end up with no memory available because the created FeatureClass doesn't release all its memory when Marshal.ReleaseComObject is called on it?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. the error "attempted to read or write protected memory" at the function FeatureClass.Search()?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your answer is #1, could you please give us the ticket number so we can follow up what's happening with it on the side of ESRI?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Joel&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2013 18:29:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/memory-leak-with-featureclass-object/m-p/584801#M15828</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-02-21T18:29:28Z</dc:date>
    </item>
  </channel>
</rss>

