以下结构是否会导致内存泄漏
本文关键字:内存 泄漏 结构 是否 | 更新日期: 2023-09-27 18:32:45
嗨,我在以下环境中托管了Web应用程序。单核,1 GB 内存,40 GB 硬盘,700 GB 带宽。当前 4-6 个用户正在研究它。有一个表单管理策略,其中所有策略都在网格视图中播放。为此,我从静态方法返回一个数据表。我的结构如下,
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;
}
我在静态类"通用数据访问"中有以下静态方法来执行命令
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;
}
上述结构(静态对象和方法)是否会导致内存泄漏?
如果有并发用户,用户是否有可能看到其他用户数据。
共享数据可能是一个问题。但是没有提到static
字段,因此这对于不同线程上的并发用户是安全的。
内存泄漏 - 否。内存消耗可能很高,但这仅取决于数据量和数据库设计的效率(W.R.T.索引等)。
CPU内核,RAM,硬盘,带宽,用户数量都与您的问题无关。