zoukankan      html  css  js  c++  java
  • ArcGIS Engine中正确释放打开资源

    转自原文 ArcGIS Engine中正确释放打开资源

    AE中对MDB,SDE等数据库操作时,打开后却往往不能及时释放资源,导致别人操作提示对象被锁定。

    很多帖子说了很多原理,看的也烦且不实用,比如一句话概括的用System.Runtime.InteropServices.Marshal.ReleaseComObject(object o)释放,说的很不清楚,很多人试过觉的释放不掉。

    事实上,的确是用该方法,但释放的技巧在于,新建几个AE对象就要逐步释放几个,例如:

    IWorkspaceFactory Fact = new AccessWorkspaceFactoryClass ();

    IFeatureWorkspace Workspace = Fact.Open(Propset,0) as IFeatureWorkspace;

      IFeatureClass Fcls = Workspace.OpenFeatureClass ("District");

    IFeatureLayer Fly = new FeatureLayerClass();

    ……

    IFeature pf

    IField pfield

    ……

    再对象运行结束时释放,如:

    System.Runtime.InteropServices.Marshal.ReleaseComObject(Fact);

    System.Runtime.InteropServices.Marshal.ReleaseComObject(Workspace);

    System.Runtime.InteropServices.Marshal.ReleaseComObject(Fcls);

    System.Runtime.InteropServices.Marshal.ReleaseComObject(Fly);

    System.Runtime.InteropServices.Marshal.ReleaseComObject(pf);

    System.Runtime.InteropServices.Marshal.ReleaseComObject(pfield);

    看到吧,千万不要以为你释放了等级最高的 IWorkspaceFactory, IWorkspace就算完事了。没办法,AE有时就这么难以理解的麻烦。

     

     

     

  • 相关阅读:
    哈希表和HashMap内部实现原理
    git入门指导
    eclipse快捷键汇总
    Java Map容器小示例
    Java容器小解析
    泛型小解析
    Python UDP编程小示例
    wcf-2
    wcf-1
    感想
  • 原文地址:https://www.cnblogs.com/arxive/p/6262803.html
Copyright © 2011-2022 走看看