How can I make sure that the objects get disposed that I am adding into the SerializationInfo
object?
For example: if I am adding a hashtable to the info object, how do I make sure that after serialization, there is no reference alive to the hastable object of my class and I can free the memory somehow?
info.AddValue("attributesHash", attributesHash, typeof(System.Collections.Hashtable));
Update (code)
[Serializable]
class A : System.Runtime.Serialization.ISerializable
{
List<int> m_Data = new List<int>();
//...
public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
{
if (m_Data != null)
{
info.AddValue("MyData", m_Data, typeof(List<int>));
m_Data.Clear();
}
m_Data = null; // <-- Will this be collected by GC?
GC.GetTotalMemory(true); //forced collection
}
};
My question is: if i make my object null after adding to the info list, will it be freed after serialization is called (when info is destroyed - I hope), or in the line when GC's function is called (which I don't think so)?
If setting 'm_Data = null' will not mark it as garbage, then how would I know that the memory occupied by m_Data has been freed or not?