より決定論的になるために、あなたはあなたの記憶がどこに行き着くかをチェックするためにいくつかの統合テストを書くべきです。これで、 WMemoryProfilerを使用して実行できます。最初に1500x1500サイズの画像をロードし、すべてをクリーンアップしてから、すべてのオブジェクトを既知としてマークします。次に、大きな画像を再配置して、どの新しいオブジェクトが割り当てられたかを確認し、それらのオブジェクトがいくつあり、誰がそれらを所有しているかを鋭く確認します。
あなたは、多くの外部モジュールが使用されていると言います。おそらく、メモリの不適切な使用のためにそれらのいくつかを削除し、それらをより良いものに置き換える必要があります。これで確認できます。
制限に達した場合でもIEnumerable<Image>
、プロバイダーが画像をロードするタイミングや、画像をキャッシュに保持する期間を決定できる場所など、プラグインがレイジー構造をサポートしている場合は、一部の画像をアンロードしてオンデマンドでロードできます。一部のメモリを解放するために参照を削除します。
[Test]
public void InstanceTracking()
{
using (var dumper = new MemoryDumper()) // if you have problems use to see the debugger windows true,true))
{
TestWith1500x1500();
dumper.MarkCurrentObjects();
TestWith3000x3000();
ILookup<Type, object> newObjects = dumper.GetNewObjects()
.ToLookup( x => x.GetType() );
// here we do find out which objects are holding most of the memory
MemoryStatistics statOld = dumper.GetMemoryStatistics();
foreach (var typeInfo in statOld.ManagedHeapStats
.OrderByDescending(x => x.Value.Count))
{
Console.WriteLine("Type {0} has {1} instances of total size {2:N0} bytes",
typeInfo.Key,
typeInfo.Value.Count,
typeInfo.Value.TotalSize);
}
// then check with the info from above who is holding the most interesting new objects.
Console.WriteLine("New Strings:"); // just an example perhaps you should have a look at the images.
foreach (var newStr in newObjects[typeof(string)] )
{
Console.WriteLine("Str: {0}", newStr);
}
}
}