标签:
很多帖子说了很多原理,看的也烦且不实用,比如一句话概括的用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有时就这么难以理解的麻烦。
标签:
原文地址:http://www.cnblogs.com/GISRSMAN/p/4551385.html