2013-09-24 69 views
0

嗨我有以下環境託管的Web應用程序。 單核,1 GB RAM,40 GB硬盤,700 GB帶寬。 Currenlty 4-6用戶正在研究它。有一個表單管理策略,其中所有策略都在gridview中顯示。爲此我從靜態方法返回一個數據表。我structuer情況如下,以下結構是否會導致內存泄漏

private void BindGrid(object sortExp) // Method to bind Grid 
{ 

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

} 

我有以下的非靜態類返回的數據表

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」靜態方法來執行命令

靜態方法
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; 
} 

上述結構(靜態對象和方法)會導致內存泄漏嗎?

如果有併發用戶,將有可能看到其他用戶數據的用戶。

回答

0

共享數據可能是一個問題。但是沒有提到的static字段,因此這對於單獨線程上的併發用戶是安全的。

內存泄漏 - 沒有。也許是內存消耗高,但這取決於數據量和數據庫設計的效率(W.R.T.索引等)。

CPU內核,RAM,硬盤,帶寬,用戶數量都與您的問題無關。

+0

確實返回一個數據表會花費高內存消耗嗎? –

+0

「,這隻取決於數據量和db設計的效率」 – user2586804

+0

感謝您的幫助 –

相關問題