私のアプリケーションでメモリが不足しているという問題があります。これは長時間走っているときには本当の問題になります。あなたは、このメソッドから見ることができるようにAddFeature
を呼び出すと、テーブルのスキーマごとに新しいデータ行を作成し、同じIDを持つすべての既存のデータ行を置き換え、GCで収集されていないDataRow
public class FeaturesDataSource{
// Table used only for schema hosting
DataTable selectedFeaturesDataTable;
IDictionary<uint, MyFeatureType > _selectedFeaturesCache =
new Dictionary<uint, MyFeatureType>();
// Create table according to a defined schema...
// Adds or replaces an existing feature
public void AddFeature(int featureID, MyFeatureType featureValue) {
DataRow row = selectedFeaturesDataTable.NewRow();
row["ID"] = featureID;
row["Content"] = featureValue;
if (_selectedFeaturesCache.ContainsKey(featureID) {
_selectedFeaturesCache.Remove(featureID);
}
_selectedFeaturesCache.Add(featureID, row);
}
}
: は、私は基本的に以下のクラスを持っています。 マイアプリケーションが1つのオブジェクト/秒の速度でタイプMyFeatureType
のオブジェクトを作成し、同じID毎回とAddFeature
を呼び出す:
// This data source gets updated in the following way
public void MethodCalledEverySecond(MyFeatureType featureValue){
// This data source contains only one object of type MyFeatureValue,
// replace the existing one by specifying a constant ID
myFeatureDataSource.AddFeature(1, featureValue);
}
これは常に新しいものと既存のデータ行を交換する必要があります。 実行時に、VSは常に1に等しい_selectedFeaturesCache
の辞書カウントを示しますが、これは予期されていますが、!dumpHeap -stat
は、常に1になるはずのメモリ内にタイプMyFeatureType
のオブジェクトの数が増えています。 何か間違っていますか? selectedFeaturesDataTable.NewRow()
は、古いデータ行への参照を置き換えてGCに収集されないようにしますか?新しい行を作成するためにNewRowを使用する場合NewRowメソッドのドキュメントによると
MyFeatureTypeオブジェクトが多くないのはなぜですか?あなたはおそらくAddFeatureを呼び出す前に作成します。 – Strelok
はい、既存のものを置き換えるためにそれらを作成します。それはクライアントの要求です:) – GETah
オブジェクトが根づいているかどうかを確認しましたか? !gcroot {id} – PHeiberg