Home > Net >  EF architecture in c # code first query problem
EF architecture in c # code first query problem

Time:10-13

I use ef6, from vs2015 NuGet access to the latest version of Sql Server 2014 database

When change the database data, the results of a query or the original data, did not update, Internet to say it's local cache, every time new,

So instead of
Private void Query ()
{
DBContext context=new MyDBContext ();
Do something...
The context. The dispose ();
The context=null;
}


Or
Private void Query ()
{
Using (DBContext context=new MyDBContext ())
{
Do something...
}
}


Can find the data in the database update is normal read here, but the memory leak happened, feeling every time new out of the context is not system recycles it, until the entire program collapse due to excessive memory footprint

Don't know what's the problem, a great god, please grant instruction. Thank you

CodePudding user response:

Only the possibility of recovery is not timely, shall not be recycled may

EF is eaten memory

You can optimize your queries, or in other lightweight framework

CodePudding user response:

when the database data change, the results of a query or the original data,
Did you saveChange?
find the data in the database update is to be able to read properly, but the memory leak happened, feeling every time new out of the context is not system recycles it, until the entire program collapse due to excessive memory footprint
Could not recycled, but every time after recycling, you open the ef link more,
In this case, you use Using,

CodePudding user response:

reference 1st floor stherix response:
only recovery may not in time, will not be recycled may

EF is eaten memory

You can optimize your queries, or in other lightweight framework


I have observed the usage of the program memory
In no change to new every time a new instance, the appearance of the program memory footprint 50 m, floating up and down, it's just a matter of cache, can't read the database to the latest data
To new every time a new instance, the program handles everything is normal, but the memory continues to grow, to grow to more than 3 g collapse...
  •  Tags:  
  • C #
  • Related