We help IT Professionals succeed at work.

Issu on deserialize an object, memory leak?

CodingCat asked
hi experts,

I would like to implement a way for user to load configurations from an .xml file and store it to an object (say a List<object> called OB).  The users may allow to open different .xml files during the process. Each time they open a different xml file, the data store OB must also be updated.
The way I'm doing it now is write a static function which will return a new List<object> from the xml file.

// class OpenSave
public static List<Object> Deserialize(string file)
    List<Object> myObject= new List<Object>();
..........// Deserialize...
    Return myObject;

When user load a different file, the following code is called:
OB = OpenSave.Deserialize(filename);

My question is, what about the old object pointed to by OB?  It seems to me the static function Deserialize create a new List object each time it is called and make OB point to this new object. Is this going to cause something like memory leak?
Watch Question


Once the list, or other object, no longer has a reference to it, it will become eligible for Garbage Collection.

See this for a quick explanation


This is a bit lengthier

There should also be more stuff on your install of MSDN (if you have it)

Good luck