I recently identified a bug with a fairly mature application I've developed which is hosted through ArcMap. The bug happens when I've loaded a 'project' into ArcMap, which includes assorted feature layers and standalone geodatabase tables. When a user chooses to close out of the active project and load a new project, I've noticed that while the previous project layers and tables appear removed from the 'Contents' view of the Table-of-Contents (TOC), the previous project geodatabase 'data source' is retained in the 'Source' view of the TOC.

The reason this is happening seems to me to be related to the fact the original call to create a new document hasn't quite finished by the time I begin loading my new data. I suppose I could track that down eventually.

But my question surrounds the TOC itself. A possible workaround might be to test the TOC during this 'load' sequence and ensure it's been properly cleared. Unfortunately, for the life of me I can't seem to identify the proper interface to acquire the collection of data sources attached to a TOC and remove the one(s) I don't want.

The closest I've come is this link which describes how to acquire the Source Contents view object/interface. Unfortunately, that particular interface (IContentsView) isn't very helpful in exposing the current collection of data sources...

I'd appreciate any thoughts, speculation and/or advice anyone might have.

  • this sounds a bit like the fact that outside of programming (even) load a data source into arcmap and it generates a lock. remove it from arcmap and the lock "can" remain. close the document and load a new document and the lock "can" remain. I could be wrong. But arcmap is not good at "releasing" data.
    – Brad Nesom
    Commented Aug 28, 2013 at 3:12
  • Ok, I solved my own problem with 'why' this was happening. I'd started loading my new data after the 'close document' event had fired, but before the 'new document' event had fired. That said, I'm still curious about how one might better access the TOC and all it's contents programmatically. Commented Aug 28, 2013 at 16:56
  • Editorial Comment: Brad, you're right. ArcMap (and other ESRI software) IS horrible at releasing data sources and properly managing object disposal. This is partly what led to this bug in the first place. If all their resources had been properly disposed at the time they fired their "DocumentClosed" event, I never would have had this problem. Commented Aug 28, 2013 at 20:18
  • Go ahead and post an answer and mark it as correct. gis.stackexchange.com/help/self-answer
    – Brad Nesom
    Commented Aug 28, 2013 at 20:22

1 Answer 1


I'd started loading my new data after the 'close document' event had fired, but before the 'new document' event had fired. As it turns out, all the 'job'/database resources haven't been completely disposed by ESRI at the time the 'close document' event fires and you have to wait till 'new document' before it's safe to move forward.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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