Do I need to release each object? Is some memory management handled for me?

6 Answers 6


Most notably, always explicitly release cursors when you are done with them. I also release some enumeration objects which imply database access, for example IEnumRelationship you get from IRelationshipClass.GetRelationshipsForObject.

Also, when you create a lot of COM instances which are short-lived (especially in tight loops), it is also a good idea to release them explicitly.

There are also scenarios when is it advisable to release individual feature (row) references. For example, if you create a new geodatabase version, edit data, reconcile&post, attempts to delete the version afterwards might fail since there might be unreleased rows, which in turn keep reference to the version (workspace) you are trying to delete. Mostly, though, such scenarios are rare and you do not need to account for them in your day-to-day ArcObjects development. It would only make the code cluttered with extraneous cleanup, making it less maintainable.

It is also important to say when not to release .NET wrappers - never explicitly release RCW of ArcObjects which might be in use by any other managed code. One example of this - do not release IMap when in ArcMap. In general, do not try to release ArcObjects which you did not create.


For the most part .NET garbage collection works well. There are some cases in ArcObjects that do important work on desctructors and the non-deterministic nature of the .NET wrappers can cause issues. This help topic covers the primary cases to be concerned about and how to manage releases.


Always destroy:

  • ICursors
  • IEnums

Be careful to not destroy something that's being used somewhere else.

Today I read a interesting discussion on ESRIs website in which Kirk participated. There were other very interesting opinions, such as the use of ReleaseComObject method and the FinalReleaseComObject (or something the like). Sorry I don't have the link on me right now.

Some even suggested to release IRows, but many agreed that it's just easier to let GC handle them directly.

I never release any IGeometry's. Anyone tried that?


I will use the ESRI.ArcGIS.ADF.ComReleaser. That being said I'm not exactly sure which arc objects use a deterministic release pattern but I mostly attach it to the IServerContext object since that is the most crucial.

using (ComReleaser comReleaser = new ComReleaser())


here's some information I was able to obtain at the 2011 esri Developer summit.

The big list I was remembering was for the singleton objects (which is two topics down in the help).

This is the link from the Best practices for using ArcObjects in .NET "Releasing COM references" topic: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Releasing_COM_references/0001000004tm000000/

And here is a post on the Geodatabase Blog to a fourm discussion that does contain a list of objects: http://blogs.esri.com/dev/blogs/geodatabase/archive/2010/05/18/what_2700_s‑up‑with‑comreleaser_3f00_.aspx

(lastly a blog post with a link to help in case the url didnt work) http://blogs.esri.com/dev/blogs/geodatabase/archive/2008/12/18/using‑the‑comreleaser‑to‑manage‑the‑lifetime‑of‑cursors‑in‑.net.aspx

  • When working with IServerContext, more crucial (than to release its .NET RCW as ComReleaser does) is to call ReleaseContext on it. Best way is to wrap the context in a .NET class implementing IDisposable (and following the standard dispose pattern including implementing the finalizer)
    – Petr Krebs
    Apr 4, 2011 at 18:55
  • @Petr yes releaseContext is huge and something I haven't overlooked but thanks for putting it in writing for everyone else.
    – Steve
    Apr 4, 2011 at 21:26
  • 2
    I believe that ComReleaser is part of a 32bit assembly meaning that you won't be able to run ComReleaser in a 64bit process (e.g. ArcGIS Server). I was writing an SOE and got burned on this.
    – bcollins
    Jul 30, 2013 at 14:36
  • are there other options for Server releasing?
    – VBAHole
    Sep 25, 2017 at 18:51
  • @VBAHole not that I've noticed. Even at 10.5.1 arcobjects.
    – Steve
    Sep 26, 2017 at 23:38

Don't forget IWorkspace objects. At the ESRI dev Summit a couple of years ago, I asked the question, and the answer from ESRI was ICursor and IWorkspace objects.

  • There is no point to releasing workspaces because they are cached by the workspace factory singletons.
    – Preston
    Nov 20, 2013 at 23:58

are the rules different when working with Server Objects like a Cursor in an SOI? I'm trying to use ComReleaser but it fails every time it gets anywhere near the method in my SOI code

  • Don't post a question as an answer to an existing question. Post it as a new question, with a link to the existing one.
    – Bjorn
    Sep 25, 2017 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.