LINQ DataContext caches all read objects in the DataContext, even if you do not have references to them. If you request the object later, you get a cached version.
Instead of executing GC.Collect() you should clear the caches in the LINQ context, here is a blog post describing how.
In short:
const BindingFlags FLAGS = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; var method = context.GetType().GetMethod("ClearCache", FLAGS); method.Invoke(context, null);
In LINQPad, you should replace context with this .
source share