[fdo-users] RE: .net Wrapper quirks

Clayton Hotson clayton.hotson at autodesk.com
Sat Jul 24 10:27:22 EDT 2010


Bohne,

Jackie is saying the same thing - you are effectively leaking when you use these compound statements (X.Y.Z) when Y is disposable.  This is because the GC cannot keep up with de-allocation, and so must be treated as deterministic, like unmanaged C++.

Every time you use insert.PropertyValues.<Whatever> you are actually *creating* a reference to PropertyValues (a PropertyValueCollection object in FDO) and bumping the unmanaged ref count.  This reference created by this code must be disposed, or it will effectively leak...and cause your access violations down the road.  You are not disposing of this value...

The code you updated does not actually change anything.  Try something like this instead (forgive the pseudocode - I'm away from any development machine):

...

PropertyValueCollection propCollection = insert.PropertyValues // Create your *one time* accessor here...

using (IFeatureReader sourceReader = select.Execute())
{
propCollection.Clear();
...
propCollection.Add(xxx);
...
}

propCollection.Dispose(); // Dispose of it - basically call Dispose() on *anything* that is disposable...

// Do NOT use insert.PropertyValues.Create() or insert.PropertyValues.Add() or PropertyValues leaks.

Follow this logic in *all* your .NET allocations, particularly those inside your inner loops and you will avoid these access violations.  For instance, you cannot therefore use foreach for disposable elements in a collection unless you call dispose explicitly...

Clayton


On SatJul 24, 2010, at Sat Jul 24, 8:36 PM, Jackie Ng wrote:


Try this:

Instead of clearing and adding everytime you read a feature, load the
IInsert's property values with the right DataValue/GeometryValue objects
using the Class Definition *once*.

Then in your loop, instead of clearing the collection and adding fresh
instances, go through the existing DataValue/GeometryValue setting them to
null (using SetNull()) first and then update these values with the ones from
your reader.

For extra stability, you could cache these DataValue/GeometryValue objects
in a dictionary (using the property name as the key) and everytime you need
to SetNull() and update the values use the dictionary instead of the
PropertyValueCollection. The insert will still work because the
PropertyValueCollection is holding the same DataValue/GeometryValue
references as the ones in your dictionary.

This is how I do it in FDO Toolbox, and it has been very stable thus far.

http://code.google.com/p/fdotoolbox/source/browse/trunk/FdoToolbox.Core/ETL/Operations/FdoOutputOperation.cs

- Jackie
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/net-Wrapper-quirks-tp2049912p5332651.html
Sent from the FDO Users mailing list archive at Nabble.com.
_______________________________________________
fdo-users mailing list
fdo-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/fdo-users



More information about the fdo-users mailing list