首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以下结构是否会导致内存泄漏?

以下结构是否会导致内存泄漏?
EN

Stack Overflow用户
提问于 2013-09-24 10:59:42
回答 1查看 495关注 0票数 0

嗨,我有以下环境托管的web应用程序。单核,1GB RAM,40 GB硬盘,700 GB带宽。目前有4-6个用户正在使用它。有一个表单管理策略,其中所有策略都在网格视图中被淡化。为此,我将从静态方法返回datatable。我的结构如下,

代码语言:javascript
复制
private void BindGrid(object sortExp) // Method to bind Grid
{

    DataTable dt = PolicyAccess.GetAllPolicy(some parameters for filter);
    GRV1.DataSource = dt; 
    GRV1.DataBind();
    dt.Dispose();

}

在非静态类中有以下返回datatable的静态方法

代码语言:javascript
复制
public static DataTable GetAllPolicy(string pmPolicyNo, int type)
{
    // get a configured DbCommand object
    DbCommand comm = GenericDataAccess.CreateCommand();
    // set the stored procedure name
    comm.CommandText = "proc_docGetAllPolicy";

    // create a new parameter
    DbParameter param = comm.CreateParameter();
    param.ParameterName = "@pmPolicyNo";
    param.Value = pmPolicyNo;
    param.DbType = DbType.String;
    comm.Parameters.Add(param);


    // create a new parameter
    param = comm.CreateParameter();
    param.ParameterName = "@Type";
    param.Value = type;
    param.DbType = DbType.Int32;
    comm.Parameters.Add(param);

    // execute the stored procedure and save the results in a DataTable
    DataTable table = GenericDataAccess.ExecuteSelectCommand(comm);
    return table;
}

我在静态类"GenericDataAccess“中使用下面的静态方法来执行命令

代码语言:javascript
复制
public static DataTable ExecuteSelectCommand(DbCommand command)
{
    // The DataTable to be returned 
    DataTable table;
    // Execute the command making sure the connection gets closed in the end
    try
    {
        // Open the data connection 
        command.Connection.Open();
        // Execute the command and save the results in a DataTable
        DbDataReader reader = command.ExecuteReader();
        table = new DataTable();
        table.Load(reader);

        // Close the reader 
        reader.Close();
    }
    catch (Exception ex)
    {
        Utilities.LogError(ex);
        throw;
    }
    finally
    {
        // Close the connection
        command.Connection.Close();
    }
    return table;
}

// creates and prepares a new DbCommand object on a new connection
public static DbCommand CreateCommand()
{
    // Obtain the database provider name
    string dataProviderName = NandiConfiguration.DbProviderName;
    // Obtain the database connection string
    string connectionString = NandiConfiguration.DbConnectionString;
    // Create a new data provider factory
    DbProviderFactory factory = DbProviderFactories.
    GetFactory(dataProviderName);
    // Obtain a database specific connection object
    DbConnection conn = factory.CreateConnection();
    // Set the connection string
    conn.ConnectionString = connectionString;
    // Create a database specific command object
    DbCommand comm = conn.CreateCommand();
    // Set the command type to stored procedure
    comm.CommandType = CommandType.StoredProcedure;
    // Return the initialized command object
    return comm;
}

上述结构(静态对象和方法)是否会导致内存泄漏?

如果有并发用户,用户是否可能看到其他用户数据。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-24 11:07:56

共享数据可能是一个问题。但是没有提到static字段,因此对于在不同线程上的并发用户来说,这是安全的。

内存泄漏-不。可能内存消耗很高,但这仅仅取决于数据量和数据库设计的效率(W.R.T.索引等)。

CPU内核、RAM、硬盘、带宽、用户数量都与您的问题无关。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18979758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档