Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
pDL.Disconnect()
pMxDoc.FocusMap.DeleteLayer(pPtLayer)
pMxDoc.UpdateContents()
pMxDoc.ActiveView.Refresh()

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)

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
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 '12 at 19:10
    
Interesting. And all references to ArcObjects variables are released? (set = nothing)? –  Jakub Apr 10 '12 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 '12 at 20:04
    
Right. I was thinking of VB6 –  Jakub Apr 10 '12 at 20:47
2  
Did you try calling IGpUtilities2.RemoveInternalLayer? –  Kirk Kuykendall Apr 10 '12 at 21:17
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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