fannonj

Strange error using search cursor - std::bad_alloc at memory location

Discussion created by fannonj on Sep 6, 2010
Latest reply on Sep 10, 2010 by Neil
Hi

I've got some code that uses a search cursor on several feature classes within a loop. I've implemented Marshal.ReleaseComObject() on the cursor but am getting a strange COM related error when processing a large number of features.

The error is:

First-chance exception at 0x7c812afb in ArcMap.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012f1e8.

This seems to be occurring after a call to NextFeature() on the cursor and does not occur consistently at a given record, so I am discounting anything wrong with the data.

Anyone got any idea what's causing this? I'd appreciate some help in resolving it as I have read most of the docs and examples on correct usage of cursors and I'm sure I'm doing it correctly.

An extract of the code is included below. I'm using ArcGIS Desktop 9.3.1 Sp1 on XP and C# in Visual Studio 2008. The data is coming from a Personal GDB.


...

//Query each node featureclass in turn to find intersecting points
foreach (IFeatureClass pNodeFC in m_nodeFCList)
{
    IDataset pNodeDataset = (IDataset)pNodeFC;
    String sNodeFCName = pNodeDataset.Name;

    //set the geometry field for the spatial filter and perform the query
    pSpatialFilter.GeometryField = pNodeFC.ShapeFieldName;
    pSpatialFilter.WhereClause = m_nodeWhereClause;

    IFeatureCursor pNodeCursor = pNodeFC.Search((IQueryFilter)pSpatialFilter, false);
    IFeature pNodeFeature = pNodeCursor.NextFeature(); //ERROR OCCURS HERE

    IPoint pNodePoint;
    IPoint pOutPoint = new PointClass();
    Double dDistFrom = 0;
    Boolean bRightSide = true;

    while (pNodeFeature != null)
    {
        //Get the distance the point is located along the line
        Double dDistAlong = 0;
        pNodePoint = (IPoint)pNodeFeature.ShapeCopy;
        pOriginalLine.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pNodePoint, false, pOutPoint, ref dDistAlong, ref dDistFrom, ref bRightSide);

        //Check the point isn't at the start or the end of the line
        if (!((dDistAlong == 0) || (dDistAlong == dLineLength)))
        {
            //Not at start or end so add to split list
            SplitFeature splitFeat = new SplitFeature(pNodePoint, sNodeFCName, pNodeFeature.OID, dDistAlong);
            splitList.Add(splitFeat);
        }

        //get next feature
        pNodeFeature = pNodeCursor.NextFeature();

    } //end while

    //Release COM Objects
    Marshal.ReleaseComObject(pNodeCursor);

} //end for

...

Outcomes