Reputation: 39
I'm using the following code to insert or update object.
The context or any object is not returned outside of the method. So no object is referenced outside of the method. But if i keep the loop going, i need up using 2 GB or memory at some point.
On checking turns out objects are never removed from memory. Even though I have used new contexts within using blocks. Why garbage collector isnt collecting those objects. Also tried GC.Collect() but nothing changes. What am I doing wrong?
Updated Code:
I think using a extension method was the issue. I'd love know what exactly and how exactly fixed it but the following code checked my memory leak
Upvotes: 1
Views: 903
Reputation: 1390
GC collects all unused objects (accept for the open streams and connections), so GC is not the problem - it`s in the code. Try splitting your code into separate methods/clases based on SOLID. Then memory profiler if needed.
There is no chance to degug your code without your Database. So just general answer, sorry.
Upvotes: 2