我有一个功能:
private void FindEmployees(object source, MyEventArgs e)
{
using (SqliteConnection conn = new SqliteConnection(connectionString))
{
conn.Open();
using (MyDataContext db = new MyDataContext(conn))
{
IQueryable<Employee> employees = from g in db.Employees
where g.Name == e.Name
orderby g.Name
select g;
if (employees.Count() == 0)
{
MessageBox.Show("Not found");
}
else
{
Employee employee = employees.First<Employee>();
txtAddress.Text = employee.Address;
}
}
}
}
我的程序每 3 秒使用随机“e.Name”(来自 DB 的真实姓名)调用此函数以测试内存泄漏。12 小时后,Linux 杀死了我的程序,因为它已经吃掉了所有空闲内存。
拜托,有人帮帮我!
如果我评论下面的行,则没有泄漏!
Employee employee = employees.First<Employee>();
txtAddress.Text = employee.Address;