IFeatureCursor.NextFeature not releasing memory

953
3
Jump to solution
08-12-2010 08:29 PM
ElmorFigio
New Contributor III
I've got a non recycling cursor retrieving features into a `List<IFeature>`. 

When I populate the list, I can see my memory usage climbing up.  When I discard my list (or it goes out of scope), the memory doesn't go down again, even when explicitly calling the garbage collector. 

I've tried looping through the list and calling ReleaseComObject on each IFeature, also to no avail. 

This is an issue, as my app does this whenever a given user action is performed, and the memory usage just keeps climbing, till there's no memory left on the machine and it crashes.

This is driving me nuts.  Any ideas?
1 Solution

Accepted Solutions
ElmorFigio
New Contributor III
This topic was addressed and resolved over at http://gis.stackexchange.com/questions/1133/ifeaturecursor-nextfeature-not-releasing-memory

Thanks for our help though McCancey

View solution in original post

0 Kudos
3 Replies
JanDuske
New Contributor
I've just made a test on this issue. This simple function is called in an inifite loop:

        
private static void check(IFeatureWorkspace fws)
        {
            IFeatureCursor c = fws.OpenFeatureClass("XYZ").Search(null, false);
            IFeature f = c.NextFeature();
            m_List = null;
            GC.Collect(2);
            m_List = new List<IFeature>();
            while (f != null)
            {
                m_List.Add(f);
                f = c.NextFeature();
            }
            Marshal.FinalReleaseComObject(c);
        }


Each time the function is called the memory usage drops to approximately the size it had before the last cursor loop, maybe a few KB more.
Can you post you critical code? Are you sure that there's no other operation involved which might increase memory usage, like in a ClassExtension fireing for each user action?
0 Kudos
ElmorFigio
New Contributor III
This topic was addressed and resolved over at http://gis.stackexchange.com/questions/1133/ifeaturecursor-nextfeature-not-releasing-memory

Thanks for our help though McCancey
0 Kudos
DonnyVelazquez
Occasional Contributor

For anyone having this issue in 10.4.1. Looks like its a bug in ArcObjects. Doesn't get fixed until 10.5.1. 

arcobjects - IFeatureCursor.NextFeature not releasing memory - Geographic Information Systems Stack ... 

0 Kudos