How to clear an object context

If I have done several queries and the ObjectContext was filled with entities, how can I clear the context if I no longer need these objects. I know that I need to get rid of the context as soon as possible, but in this case this is not possible. So, is there a way to remove these objects from the context?

+4
source share
3 answers

You can try Disconnect each entity in context.

+1
source

There is no way to "clean up" an ObjectContext. The only way to do this is to delete the current instance of the ObjectContext and start a new instance.

+11
source

You can try to detach each object in context.

Max is right, but when you want to do something that takes a lot of time, the context stores many objects and continues to grow in memory and slows down your application.

It causes a memory leak.

I have this problem with EntityFramework 6 now, but I donโ€™t know how to "exactly" fix it.

Whenever I need to make a request, I get the context and do it, but this action is different, I have a lot of things to calculate in a loop, and I keep the context to the end. At the moment, I delete my list after a flash, but I still have leak memory in my system, and the context has this problem with certainty. Anyone suggest a "team"? I do not know if the entity infrastructure works.

0
source

All Articles