Removing Shapefile layer with Labels leaves a LOCK

Discussion created by jeremyfon001 on Jul 3, 2012
Latest reply on Jul 3, 2012 by jeremyfon001
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?

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;