BlairServicessLLC

Releasing COM Objects on Desktop and in Citrix

Discussion created by BlairServicessLLC on Nov 30, 2013
Latest reply on Dec 2, 2013 by agray1
I recently completed a process where I built and tested a command in ArcMap using the ArcObjects SDK.  The command makes extensive use of objects in the Geodatabase, Carto and Geometry namespaces.  As is strongly advised I made sure all cursors created when querying the Geodatabase are released when the command is done with them (using Marshal.ReleaseComObject).  The command was tested extensively on other desktop machines and numerous issues rooted out. By the time it was to deliver to the client I was feeling pretty good.

But the client had a Citrix application server.  And when the command was installed there we quickly discovered it to fail in ways it had never failed in all of our desktop testing.

After multiple mis-diagnoses and considerable stress and strain we found that other COM objects needed to be released as well.  A particular case in point was this:

(ISegmentCollection) segCol = (ISegmentCollection)curvePolyline;
(IEnumSegment) polySegments = segCol.EnumSegments;
int outPartIndex = 0;
int outSegIndex = 0;
int partIndex = 0;
polySegments.Next(out polySegment, ref outPartIndex, ref outSegIndex);
while (polySegment != null)
{
    switch (polySegment.GeometryType)
    {
         case esriGeometryType.esriGeometryLine:
              // do stuff
              break;

         case esriGeometryType.esriGeometryPolyline:
              // do stuff
              break;

         case esriGeometryType.esriGeometryCircularArc:

              (ICircularArc) circArcPart = (ICircularArc)polySegment;
              // do stuff
             break;
       }
       polySegments.Next(out polySegment, ref outPartIndex, ref outSegIndex);
}

When this was altered to release the polySegment, polySegments and segCol objects on completion of the "while" loop and when the circArcPart object was released after use (and other similar changes) the code worked reliably.

After the fact I heard from other developers that Citrix is, for whatever reason *way* more sensitive to COM object life span management than desktop applications.

So..... my question is, what makes Citrix so sensitive?  And more importantly, are there guidelines for COM object management for Citrix that would supplement the general information ESRI provides on releasing COM objects?

Thanks,
Ed

Outcomes