ERROR

Layer in Use- Maximum number of streams exceeded

Last Published: April 25, 2020

Error Message

Looping through a recordset using IFeatureCursor may cause the following error:

"Layer in Use- Maximum number of streams exceeded"

Cause

Garbage collection takes care of releasing resources in managed code. This process is non-deterministic and will release resources at some undetermined time. In most cases this approach works fine, however in this situation it is necessary to mark the COM object as eligible for garbage collection so the resources will be released in a timely manner.

Solution or Workaround

The following steps show how to mark the COM object as eligible for garbage collection.

  1. At the top of the class module add the namespace as shown below:


    Code:
    C#:
    using System.Runtime.InteropServices;

    VB.Net:
    Imports System.Runtime.InteropServices

  2. In the method using the FeatureCursor, add the following code to mark the feature cursor as eligible for garbage collection.

    Code:
    Marshal.ReleaseComObject(pFeatCursor)

Article ID:000005969

Software:
  • ArcMap 8 x
  • ArcMap 9 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic