像arcobjects这种基于COM组件开发有时候遇到资源锁住的问题还是挺烦恼的。
今天工作中遇到的问题,搞了半天才解决。
在做拓扑脏区显示时候,图层以featurelayer的形式从mdb中加载的。所有工作完成后需要删除临时创建的topo数据库发现怎么都删除不了,检查了一遍又一遍确认所有资源都已经强制释放掉了然而mdb还是锁死状态。百思不得其解,最后还是通过查找帮助文档才发现的问题。
在图层清除的时候调用的IMap.clearlayers的方法,官方文档描述为:
ClearLayers removes all layers types from the Map. ClearLayers does not change or reset the Map's spatail reference however. In addition, ClearLayers does not affect any graphics stored in the Map's BasicGaphicsLayer - it's not a true Layer. ClearLayers does not update the contents view (TOC) or the display.
而真正该去调用的应该是deletelayer。
DeleteLayer will automatically recalculate the Map's extent after the successful deletion of a layer.
Tips:
If a layer is selected in the TOC window (
IMxDocument::SelectedLayer), you can pass this to DeleteLayer.
When deleting a layer that references a feature class, like a FeatureLayer, executing
IDataLayer2::Disconnect will ensure that references to the feature class are cleared.
看来以前写法都不太对,平时遇到问题还是需要多看看帮助文档。