[fdo-users] RE: .net Wrapper quirks
clayton.hotson at autodesk.com
Sat Jul 24 06:49:59 EDT 2010
Try avoiding compound statements like the one you use to clear and add to the insert command's property values - insert.PropertyValues.Clear() and insert.PropertyValues.Add(). Instead try caching a variable outside the loop which represents the return from PropertyValues - and Dispose() it after the loop exits (the way it is written below, a PropertyValueCollection reference is actually created *twice* for each item in the reader, and never disposed, since PropertyValueCollection is also disposable).
I have seen this behavior you report many, many times, and I believe it is related to the generational nature of the garbage collector in .NET not being able to keep up with allocations made during statements like 'insert.PropertyValues.xxx()', especially in loops, and this is why the exception occurs somewhat randomly but only after a certain amount of data is processed.
Basically, there should be an explicit Dispose() called for every, single IDisposable object you access in FDO - and in loops with large amounts of data this must be taken to the absolute extreme. The 'using' is useful (as you use) and it can lead to perhaps difficult-to-read code, but you might also consider try-finally blocks for disposal of multiple objects.
As Jackie says, it is not necessary to call Dispose() on objects you wrap in the using statement, as this is done automatically when it exits scope.
Anyway, I hope this helps!
On SatJul 24, 2010, at Sat Jul 24, 6:02 PM, Bohne wrote:
thanks for your reply.
I modified my code but still no luck. Even if I'm adding only one integer
value to my Insertcommand (without reading from source) i'm getting this
Exception ( less than before, but still there) ??
private void writeValues(FDO.IFDOSource source, FDO.IFDOSource target,
//Open Source Connection, if necessary
if (source.Connection.ConnectionState !=
//Open Target Connection, if necessary
if (target.Connection.ConnectionState !=
//Creating Select Command
ISelect select =
if (graphics.Filter.Length > 0)
using (IInsert insert =
int counter = 0;
using (IFeatureReader sourceReader = select.Execute())
//Clear old insertcommand
//Adding PropertyValues to InsertCommand
bool writeRecord = true;// fillRow( insert, source,
sourceReader, target.MyFeatureClass, graphics, counter);
using (IFeatureReader insertReader =
View this message in context: http://osgeo-org.1803224.n2.nabble.com/net-Wrapper-quirks-tp2049912p5332467.html
Sent from the FDO Users mailing list archive at Nabble.com<http://Nabble.com>.
fdo-users mailing list
fdo-users at lists.osgeo.org<mailto:fdo-users at lists.osgeo.org>
More information about the fdo-users