for (int i = 0; i < 10000; i++) { db.Prodcuts.Add(new Prodcut { CategoryId = 1, Creatime = DateTime.Now, ProductName = "Hello Kitty!" }); } ViewBag.Time1 = sw.ElapsedTicks; db.SaveChanges();
运行这样的代码后,内存会吃掉很多,因为有db这个context,请问在保存数据结束后怎么释放内存?
using(DbContext db = new DbContext)
{
for (int i = 0; i < 10000; i++)
{
db.Prodcuts.Add(new Prodcut { CategoryId = 1, Creatime = DateTime.Now, ProductName = "Hello Kitty!" });
}
ViewBag.Time1 = sw.ElapsedTicks;
db.SaveChanges();
}
也就等同于 db.Dispose()?