I am testing the memory usage of EF5 vs. EF6.1 (code first, POCO, ProxyCreation enabled) and came across some concerning behavior.
My test is simple:
1) Check memory using GC.GetTotalMemory(false)
2) Run ~20 complex queries through different DataContexts, keep references to all results throughout
3) Compare memory using GS.GetTotalMemory(false)
4) Clear references to everything
5) Compare memory ssing GC.GetTotalMemory(true) (forces garbage collection
Comparing the memory from (3) to (5) gives me an idea of how much memory has been allocated by EF in the process.
There was little difference between EF5 and EF6.1
However there is a substantial difference between compiling in Debug mode vs Release mode:
Debug mode: ~150MB allocated
Release mode: ~280MB allocated
I have verified these results as follows:
Comparable results appear in Task Manager (private working set)
Same for EF5 and EF6.1
Same for running within Visual Studio and running EXE directly
On a workstation with no other programs running
There are no [if #debug] statements within my code
What could possibly be the cause, and how could I investigate further?