I'm working on some code for a button in ArcGIS 9.2 using Visual Studio 2005. The process adds a point layer, performs a select by location, exports the attributes of the selected points, then removes the point layer. The code I'm using to remove the point layer at the end of the process is:

Dim pDL As IDataLayer2 = pPtLayer 'QI

But there are remnants of the point layer remaining after the process has completed. In the command window, a list of the layers indicates it is still being referenced. This is causing to button to perform incorrectly if it is used multiple times in a session. How can I remove the layer without leaving these 'artifact' references?

(Also posted at http://forums.arcgis.com/threads/54771-Data-References-Remain-After-Calling-DeleteLayer)


1 Answer 1


I tried to get similar results in version 10 using the toolbox Delete Tool. When the dialog box opens my shapefile is available in the combo box. While it is still open I use a tool that has similar code to yours that deletes the layer and refreshes everything. The combo box in the Delete Tool has not been updated and still shows the shapefile as available. If I close the dialog and open it again the shapefile is no longer listed.

I wonder if you have to physically close and re-open the command window. You could also try saving the mxd right after you delete the layer.

  • I haven't been opening the command window until the process runs to completion, so I'd expect the references to be gone already. This tool is designed to be distributed to potentially 100+ people, who may not appreciate an involentary save.
    – Bjorn
    Apr 10, 2012 at 19:10
  • Interesting. And all references to ArcObjects variables are released? (set = nothing)? Apr 10, 2012 at 19:19
  • No, I haven't been doing that. A suggestion on the Esri forums mentioned using the ComReleaser class. Will setting all of the variables to Nothing achieve the same thing?
    – Bjorn
    Apr 10, 2012 at 20:04
  • Right. I was thinking of VB6 Apr 10, 2012 at 20:47
  • 2
    Did you try calling IGpUtilities2.RemoveInternalLayer? Apr 10, 2012 at 21:17

Your Answer

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

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