Releasing COM Objects on Desktop and in Citrix

725
4
11-30-2013 02:30 PM
EdwardBlair
Occasional Contributor
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
0 Kudos
4 Replies
RichardWatson
Regular Contributor III
I worked on a large commercial product which was developed on ArcObjects and ran on Citrix.  To the best of my knowledge, we never had a Citrix specific issue.

You did not explicitly state what failed in your program but I'll assume that it was related to out of memory issues.  In this case it might make sense to compare the operating systems of the desktop systems that you tested on versus the operating system of the server hosting Citrix.

What version of ArcMap are you using?
Did you examine the NT event log on the server?
Which server operating system are you running?
Is the server operating system a 64 bit OS?
How much physical memory does the server have?
How much virtual memory does the server have?
How many users were/are using the server simultaneously?

My best guess is that you are running out of virtual memory.
0 Kudos
EdwardBlair
Occasional Contributor
Richard -

Thanks for the reply.

I'm sure virtual memory was running out.  Originally the environment was set to allocate no more that 4GB to the paging file.  When this was changed to allow the system to manage it automatically there was some improvement, but would still crash -- often.

The typical error message was: "R6025 - C++ Pure Virtual Function Call".  This was not caught in any try/catch block and ArcMap exited rapidly afterward.  No evidence was present in the event log -- at least none I could find.

The development OS was Windows 7-64 bit.  The Citrix server runs Windows 2008 R2 �?? 64 bit.  Would you suggest that that is the significant difference?

Ed
0 Kudos
RichardWatson
Regular Contributor III
Server is a environment where all physical resources (CPU, physical memory, paging files, etc.) are shared across all users.

My best guess is that you are running out of server resources.  I was trying to get at that with the some of the questions I asked.

One thing that you should check is to make sure that the ArcMap processes are actually exiting, i.e. they are not in some type of zombie state which consumes resources.  I recommend the SysInternals Process Explorer tool.

Best of luck!
0 Kudos
AlexanderGray
Regular Contributor II
I have dealt with citrix and ArcGIS desktop 8.3 and 9.2, the app was properly written but extremely inefficient.   Things to watch out for are anything to do with the graphics card or display (cached based maps, dynamic layers, etc.)  A big difference between your dev workstation and the citrix server is drawing accross the network.  If you don't do regression testing with a citrix server, you have no way of validating your application.

On the dev side it was sluggish but ok, on the citrix side, it ran but very very slow.  The problem was the cpu load on the citrix server.  The servers were sized with some rather optimistic expectations, ArcGIS desktop tends to be a resource hog at the best of times, the custom implementation resource usage was very bad so the system did not scale.  Citrix will make any problem of your system very unforgiving because the resources are shared amongst many user.

cheers
0 Kudos