From: Tony Johansson on 1 May 2010 18:39 many thanks. I had looked at the wrong question. //Tony
From: PvdG42 on 2 May 2010 09:24
"Tony Johansson" <johansson.andersson(a)telia.com> wrote in message news:OUFtlHU6KHA.1888(a)TK2MSFTNGP05.phx.gbl... > > I see what you mean but assume that I create a person object from the > Person class like this > Person myPerson = new Person(add some data here to the c-tor); > > I never used to set null to the object like this > myPerson=null; > So If I don't do this will this object myPerson never be garbage collected > because you will still have a reference. > > So do you mean that when I'm finish with an object assign null to the > object > > //Tony > As I see the issue was resolved in another response, this is of little value to the thread. However, my reference was from C++, which has no automatic garbage collection. Thus, the object is destroyed using delete, leaving the pointer (potentially) to cause issues. In your C# example, the rules of scope also apply, so once the block of code where your object and object variable were created finishes executing, both are gone. |