Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the .NET MethodInfo cache be cleared or disabled?

Per MSDN, calling Type.GetMethods() stores reflected method information in a MemberInfo cache so the expensive operation doesn't have to be performed again.

I have an application that scans assemblies/types, looking for methods that match a given specification. The problem is that memory consumption increases significantly (especially with large numbers of referenced assemblies) since .NET hangs onto the method metadata.

Is there any way to clear or disable this MemberInfo cache?

like image 670
Anton Avatar asked Oct 30 '25 22:10

Anton


1 Answers

I don't think so. One trick would be to do this work in an AppDomain. You could create a new AppDomain, do all of your work, report your results, then unload the AppDomain. Not a trivial task and fairly slow but it is the only way to effectively unload assemblies or reflection related caches (that I know of).

like image 153
justin.m.chase Avatar answered Nov 03 '25 19:11

justin.m.chase