.NET MethodInfo缓存是否可以清除或禁用? [英] Can the .NET MethodInfo cache be cleared or disabled?

查看:70
本文介绍了.NET MethodInfo缓存是否可以清除或禁用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个 MSDN ,调用反映的Type.GetMethods()存储MemberInfo缓存中的方法信息,因此不必再次执行昂贵的操作.

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

我有一个应用程序可以扫描程序集/类型,寻找与给定规范匹配的方法.问题在于,由于.NET挂接到方法元数据上,因此内存消耗显着增加(尤其是使用大量引用程序集时).

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.

有什么方法可以清除或禁用此MemberInfo缓存吗?

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

推荐答案

我不这么认为.一种技巧是在AppDomain中完成这项工作.您可以创建一个新的AppDomain,完成所有工作,报告结果,然后卸载AppDomain.这不是一件微不足道的任务,而且相当缓慢,但这是有效卸载程序集或与反射相关的缓存(我所知道的)的唯一方法.

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).

这篇关于.NET MethodInfo缓存是否可以清除或禁用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆