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)