Removing Shapefile layer with Labels leaves a LOCK

766
2
07-03-2012 07:34 AM
JeremyFontenault
New Contributor II
I have some code that loads a shapefile to the map, does the rendering and labels the features based on a field.  When I remove this layer from the map, a LOCK remains.  I am removing this layer the same way as I do other layers and those locks go away.  The only difference here seems to be the the labeling.  When I skip the labeling the locks go away just fine.  Also, this method I'm using is not a problem for Geodatabase feature classes, only shapefiles.

The method I'm using to create the labels is below.  I've tried using Marshal.FinalReleaseComObject and set all references to null to make sure there is nothing remaining that is causing the lock to persist.  Any suggestions?

[HTML]
private void TurnOnLabels(ILayer pLayer, string sFieldName)
        {
            IGeoFeatureLayer _pGeoLayer = pLayer as IGeoFeatureLayer;
            IAnnotateLayerPropertiesCollection _pAnnoProps = _pGeoLayer.AnnotationProperties;
            IBasicOverposterLayerProperties4 pBasic = new BasicOverposterLayerPropertiesClass();
            pBasic.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerName;
            pBasic.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
            pBasic.PolygonPlacementMethod = esriOverposterPolygonPlacementMethod.esriMixedStrategy;
            ILabelEngineLayerProperties pLabelEngine = new LabelEngineLayerPropertiesClass();
            pLabelEngine.BasicOverposterLayerProperties = pBasic as IBasicOverposterLayerProperties;
            pLabelEngine.Expression = sFieldName; //selected layer column name example [Area]
            IAnnotateLayerProperties _pAnnoLayerProps = pLabelEngine as IAnnotateLayerProperties;
            _pGeoLayer.DisplayAnnotation = true;
        }
[/HTML]
0 Kudos
2 Replies
FengZhang2
Occasional Contributor
Have you tried the following function on the layer removed?

IDataLayer2::Disconnect
0 Kudos
JeremyFontenault
New Contributor II
Yes, I am using that function as part of removing the layer.  The steps I am using are as follows:

  1. Using the Remove Layer command item for ArcGIS desktop

  2. Using the IDataLayer2 Disconnect() method.

  3. Using the IDataset.Delete() method to delete the shapefile from the disk.

  4. The use IMxDocument.UpdateContents() to update the map. FYI - it is actually this step that clears the locks from the other shapefiles.

  5. Using Marshal.ReleaseComObject to remove all Com references to the involved objects.

  6. Setting all references to null.

  7. GC.Collect()


I know some of this is overkill but I've tried everything I can think of at this point.
0 Kudos