Releasing feature class lock after editing

3190
7
01-30-2013 07:16 AM
RyanKelso
Occasional Contributor III
Basically, I've got an ArcMap project (ArcGIS version 10.0) with some custom buttons in it.  One of the buttons uses ArcObjects to change the data source of several layers from a feature class in one File geodatabase to a similar feature class in a different File geodatabase.  I've got it working so that this process releases any locks on the original feature class that was in the map (using FinalReleaseComObject).  After the data source gets switched, the button also uses ArcObjects to delete the original feature class.  All of this functionality works perfectly if no edits have been made to the data.  The button is not enabled if you are editing.

The problem I'm having is, if the user does make some edits to the data and saves the edits, then the locks on this feature class will not be released until the ArcMap application is closed, even after my button has changed the layer's data source.  I can manually remove the layers from the map, I can load a new or different map document from the File menu, but none of these things releases the lock on this feature class.  Like I said, if the user has not made or saved any edits, this all works properly.

Any ideas on how I can get the lock to go away without closing the application window?
0 Kudos
7 Replies
JasonPike
Occasional Contributor
Can you post code? A small project that reproduces the problem using the sample data ESRI delivers would be the most helpful.
0 Kudos
RyanKelso
Occasional Contributor III
I believe that this behavior may not actually have anything to do with my code.  I can very easily reproduce the problem with simple File geodatabase and a single feature class:

Add the feature class to ArcMap.  You can see the lock files created in the GDB's folder.  Remove the feature class from ArcMap and the lock files go away.

Now, add the feature class to ArcMap, make some edit, then save edits and stop editing.  Remove the feature class from ArcMap and the lock files will not go away.  Closing ArcMap will remove them.

I'm wondering, maybe there is some method that gets fired off when ArcMap is closed (that I have no clue about), which finally releases the locks after a feature class has been edited, and if it would be something I could incorporate into my code so I wouldn't have to close ArcMap.

If you still think that posting some code would help, I can certainly put something together.
0 Kudos
AlexanderGray
Occasional Contributor III
ArcMap keeps some COM objects alive after the edit session that have the locks.  When ArcMap is shutdown, the objects are destroyed which removes the locks.  ESRI's locking and especially failure to release locks has driven me crazy for years.  If you keep a reference to the featureclasses, workspace and any other objects accessed in your code and explicitly call marshal.ReleaseCOmObject (or even a finalRelease) after the layers have been removed, you may be able to release the locks.  Beware if you use the undo function after removing the layer to get it back, you might get unexpected results.
0 Kudos
RyanKelso
Occasional Contributor III
Thanks for the reply, Alexander.  I don't know if this matters, but I should clarify that any potential edits that I'm talking about here would be performed with the standard editing tools in the ArcMap UI, not anything performed in my code.  I do use FinalReleaseComObject after certain tasks to remove locks, it just doesn't work the same way if the data has been edited.
0 Kudos
JasonPike
Occasional Contributor
I believe that this behavior may not actually have anything to do with my code.  I can very easily reproduce the problem with simple File geodatabase and a single feature class:

Add the feature class to ArcMap.  You can see the lock files created in the GDB's folder.  Remove the feature class from ArcMap and the lock files go away.

Now, add the feature class to ArcMap, make some edit, then save edits and stop editing.  Remove the feature class from ArcMap and the lock files will not go away.  Closing ArcMap will remove them.

I'm wondering, maybe there is some method that gets fired off when ArcMap is closed (that I have no clue about), which finally releases the locks after a feature class has been edited, and if it would be something I could incorporate into my code so I wouldn't have to close ArcMap.

If you still think that posting some code would help, I can certainly put something together.


It sounds to me like some of the editing commands are causing memory to be leaked. I can show you how to pinpoint that:
http://forums.arcgis.com/threads/75186-Memory-leak-with-FeatureClass-object?p=263735#post263735

Mark memory before and after running an edit command that causes the lock files to stop going away. Then, diff the marks and look for things like calls to Clone methods or other calls that might prevent a geodatabase from closing by holding on to a reference. Try marking with and without the -g flag (you need to be consistent on the marks you diff--don't use -g on the before and after marks, then use -g on the before and after marks) Please post your results or ask questions if you need help.
0 Kudos
RyanKelso
Occasional Contributor III
I've solved my problem.  I incorrectly assumed that this was some kind of usual ArcMap behavior, and I simply needed to find a way to deal with it.  Thank you for your replies, Jason, while I didn't go through the debugging process you suggested, you did get me thinking along the correct lines.

Since I have a number of other ArcMap add-ins installed on my machine, I decided to uninstall all of them then test for this behavior.  After doing this, it worked fine, the locks were going away even after saving edits.  I reinstalled my current project and it still worked fine.  Using the process of elimination, I narrowed the problem down to an add-in called Attribute Assistant, from ESRI's water utilities team.  Maybe there is a memory leak, as Jason suggested, but I didn't look into it further since I don't need the Attribute Assistant anymore.  They have also updated it a number of times since I installed it, so maybe it's fixed.
0 Kudos
JasonPike
Occasional Contributor
I've solved my problem.  I incorrectly assumed that this was some kind of usual ArcMap behavior, and I simply needed to find a way to deal with it.  Thank you for your replies, Jason, while I didn't go through the debugging process you suggested, you did get me thinking along the correct lines.

Since I have a number of other ArcMap add-ins installed on my machine, I decided to uninstall all of them then test for this behavior.  After doing this, it worked fine, the locks were going away even after saving edits.  I reinstalled my current project and it still worked fine.  Using the process of elimination, I narrowed the problem down to an add-in called Attribute Assistant, from ESRI's water utilities team.  Maybe there is a memory leak, as Jason suggested, but I didn't look into it further since I don't need the Attribute Assistant anymore.  They have also updated it a number of times since I installed it, so maybe it's fixed.


Good information! Thanks for posting your solution.
0 Kudos