好的,我以为您已经直接将它们全部一起使用了
如果您没有任何缓存视图,那么为什么您的内存使用率很高?
您不能在 MVVM 应用程序中出现内存问题(即使是架构不佳的应用程序)您有哪些静态项目?
您是否曾经使用此代码来调查您的 wpf 应用程序的当前绑定情况?
private static IList<BindingInfo> getReflectPropertyDescriptorInfo()
{
var results = new List<BindingInfo>();
var reflectTypeDescriptionProvider = typeof(PropertyDescriptor).Module.GetType("System.ComponentModel.ReflectTypeDescriptionProvider");
var propertyCacheField = reflectTypeDescriptionProvider.GetField("_propertyCache",
BindingFlags.Static | BindingFlags.NonPublic);
if (propertyCacheField == null)
throw new NullReferenceException("`ReflectTypeDescriptionProvider._propertyCache` not found");
var propertyCacheItems = propertyCacheField.GetValue(null) as Hashtable;
if (propertyCacheItems == null)
return results;
var valueChangedHandlersField = typeof(PropertyDescriptor).GetField("valueChangedHandlers",
BindingFlags.Instance | BindingFlags.NonPublic);
if (valueChangedHandlersField == null)
return results;
foreach (DictionaryEntry entry in propertyCacheItems)
{
var properties = entry.Value as PropertyDescriptor[];
if (properties == null)
continue;
foreach (var property in properties)
{
var valueChangedHandlers = valueChangedHandlersField.GetValue(property) as Hashtable;
if (valueChangedHandlers != null && valueChangedHandlers.Count != 0)
results.Add(new BindingInfo
{
TypeName = entry.Key.ToString(),
PropertyName = property.Name,
HandlerCount = valueChangedHandlers.Count
});
}
}
return results;
}
使用此代码,您可以找出内存中的绑定是什么?