In our backend app based on .NET 4.6, we use a lot of Linq To Sql compiled queries. Analyzing my application with dotMemory, I noticed that some of them have a reference to the (now disposed) DataContext with which the query was originally compiled. This reference never seems to go away.
The queries themselves are not complicated. Here is an example:
private static readonly Func<DataContext, int, IQueryable<bool>> _IsEditingAllowed_Anmeldung_CompiledQuery =
CompiledQuery.Compile((DataContext db, int id) =>
db.GetTable<PersonenAnmeldung>()
.Where(p => p.Id1 == id)
.Select(p => p.Status.AllowEdit));
The shortest path of such a query is as follows:
Retention path of DataContext
Static reference: StatusLogic._IsEditingAllowed_Anmeldung_CompiledQuery ->
Func<DataContext, Int32, IQueryable<Boolean>>._target ->
CompiledQuery.compiled ->
SqlProvider+CompiledQuery.queryInfos ->
SqlProvider+QueryInfo[1] at [0] ->
SqlProvider+QueryInfo.query ->
SqlSelect.selection ->
SqlColumnRef.sourceExpression ->
MethodCallExpressionN._arguments ->
TrueReadOnlyCollection<Expression>.list ->
Expression[2] at [0] ->
LinkedTableExpression.table ->
Table<Status>.context ->
DataContext
My question is, is there any known way to circumvent this problem? Is it a problem at all, other than filling up the memory with non-used data context?