Release COM Objects in AE

When you codeing in Arc Engine, you need to consider the objects that you created, and if you leave so many unmanaged objects in the memory, and then you will find some wired activities.

You may need:

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

Or, you may use the ComComReleaser in the ArcGIS assembly ESRI.ArcGIS.ADF.Connection.Local:

  ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(pWorkFactory);

You must release the cursors with used to reach the values, and the workspaces that you used to access data.

When you get a cursor form a shpfile, then you will find a file like this in you disk:

  

And if you use the WorkspaceEdit like that:

  IWorkspace workspace = ((IDataset)pFeatureClass_para).Workspace;
  IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;

  bool startEdit = workspaceEdit.IsBeingEdited();
  if (!startEdit)
  {
    workspaceEdit.StartEditing(false);
  }
  workspaceEdit.StartEditOperation();

Then you will get a file like this:

  

Then you need stop edit the work space, like this:

  workspaceEdit.StopEditOperation();
  startEdit = workspaceEdit.IsBeingEdited();
  while (startEdit)
  {
    workspaceEdit.StopEditing(true);
    startEdit = workspaceEdit.IsBeingEdited();
  }

原文地址:https://www.cnblogs.com/henyihanwobushi/p/2983083.html