這是一個非常基本的問題。我正在調試一些內存泄漏,並完全困惑。假設我有以下幾點:.NET垃圾回收器
public class ObjectData : IDataObject
{
public int Id { get; set; }
public string Name { get; set; }
}
public class ObjectRepository<T> where T : IDataObject
{
private Dictionary<int, T> Objects;
public ObjectRepository()
{
Objects = new Dictionary<int, T>();
// load Data
}
public T GetDataObject(int id);
{
return Objects[id];
}
public Reset()
{
Objects = new Dictionary<int, T>();;
}
}
現在假設我有以下程序流程:
public Main()
{
var DataRepository = new ObjectRepository<ObjectData>();
// Constructor called and Data loaded
var myObject = DataRepository.GetDataObject(1);
DataRepository.Reset();
// Call manually the garbage collector or leave it
// Program flow continue after this
}
的問題是,將垃圾收集擺脫最初由構造函數創建的集合?或者它不會因爲程序流程中仍然引用了其中一個元素(myObject
)?
感謝您的提示!關於內部參考:) –