C#调用arcengine组件引用计数为0,但内存依然不能释放,求大神指点
public void exactData()
{
Console.WriteLine("正在提取....");
IWorkspaceFactory pFactory = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace featureworkspace = (IFeatureWorkspace)pFactory.OpenFromFile(path + "/barrier/", 0);
pFeatureclass = featureworkspace.OpenFeatureClass("road.shp");
ITable pTable = pFeatureclass as ITable;
if (pFeatureclass.FindField("value") == -1)
{
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
pFieldEdit.Name_2 = "value";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
pTable.AddField(pField);
System.Runtime.InteropServices.Marshal.ReleaseComObject(pField);
}
if (pFeatureclass.FindField("time") == -1)
{
IField pField1 = new FieldClass();
IFieldEdit pFieldEdit1 = pField1 as IFieldEdit;
pFieldEdit1.Name_2 = "time";
pFieldEdit1.Type_2 = esriFieldType.esriFieldTypeDouble;
//pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
pTable.AddField(pField1);
System.Runtime.InteropServices.Marshal.ReleaseComObject(pField1);
}
IFeatureCursor cursor = pFeatureclass.Update(null, false);
IFeature feature = cursor.NextFeature();
IRaster pRaster = p_Raster;
int zFieldIndex = pFeatureclass.FindField("value");
int lenindex = pFeatureclass.FindField("Shape_Leng");
int speindex = pFeatureclass.FindField("speed");
int timeindex = pFeatureclass.FindField("time");
int i = 0;
while (feature != null)
{
++i;
IPolyline polyline = feature.Shape as IPolyline;
IPoint mid =DataUtils.getLineCenterPoint(polyline);
try
{
double zValue = Get_value(mid.X, mid.Y, pRaster);
feature.set_Value(zFieldIndex, zValue);
feature.set_Value(timeindex, double.Parse(feature.get_Value(lenindex).ToString()) * 60 / (double.Parse(feature.get_Value(speindex).ToString()) * 1000));
cursor.UpdateFeature(feature);
//Console.WriteLine(i);
GC.Collect();
Console.WriteLine(System.Runtime.InteropServices.Marshal.FinalReleaseComObject(mid) + "," + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(polyline) + "," + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(feature));
//打印都是0,0,0,但内存依然上升很快,要处理180w条记录,一下子就内存溢出
;
;
mid = null;
polyline = null;
feature = null;
feature = cursor.NextFeature();
//
}
catch (Exception ex)
{
//MessageBox.Show(i + "抛出异常");
Console.WriteLine(ex.ToString());
logError.Error("提取值出错!");
}
}
cursor.Flush();
//System.Runtime.InteropServices.Marshal.ReleaseComObject(feature);
// System.Runtime.InteropServices.Marshal.ReleaseComObject(pTable);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cursor);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pRaster);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(p_Raster);
feature = null;
cursor = null;
pRaster = null;
p_Raster = null;
//MessageBox.Show("t提取完成");
logInfo.Info("提取完成");
}