如何减少程序的内存使用量?

时间:2015-07-03 09:49:26

标签: c# memory

我正在从地理数据库文件中提取的数据中创建(空间数据库文件)sdf文件。我不是存储数据的任何地方仍然存储器和程序的CPU使用率非常高。我使用具有庞大数据库的文件如何才能提高性能?我也尝试过使用finalize和dispose方法。

static void GetFeatureData(Geodatabase geodatabase, string tablename, string sdffilepath)
{
    string query = "select * from " + tablename;
    int no = 1;

    foreach (Row row in geodatabase.ExecuteSQL(query))
    {
        IConnection con = OpenFDOSDFConnection(sdffilepath);
        IInsert insertCommand = (IInsert)con.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_Insert);
        insertCommand.SetFeatureClassName(tablename);
        for (int nFieldNumber = 0; nFieldNumber < row.FieldInformation.Count; nFieldNumber++)
        {
            string fieldName = row.FieldInformation.GetFieldName(nFieldNumber);
            switch (row.FieldInformation.GetFieldType(nFieldNumber))
            {
                case FieldType.SmallInteger:
                    if (row.IsNull(fieldName))
                    {
                        insertCommand.PropertyValues.Add(new PropertyValue(fieldName, null));
                    }
                    else
                    {
                        insertCommand.PropertyValues.Add(new PropertyValue(fieldName, new Int32Value(row.GetShort(fieldName))));
                    }
                    break;
                //All other datatypes

                case FieldType.Geometry:
                    if (!row.IsNull(fieldName))
                    {
                        switch (row.GetGeometry().geometryType.ToString())
                        {
                            case "Point": insertCommand.PropertyValues.Add(new PropertyValue("Geometry", geometryValue));
                                break;
                            //All other Geometry cases        
                        }
                    }

            }
            insertCommand.Execute();
            insertCommand.Dispose();
            con.Dispose();
            Console.WriteLine(no++);
        }
    }
}  

0 个答案:

没有答案