Error: Layer in Use- Maximum number of streams exceeded
Looping through a recordset using IFeatureCursor may cause the following error:
"Layer in Use- Maximum number of streams exceeded"
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.
- At the top of the class module add the namespace as shown below:
- In the method using the FeatureCursor, add the following code to mark the feature cursor as eligible for garbage collection.