How do i free objects in C#

后端 未结 9 1729
傲寒
傲寒 2021-01-01 21:53

Can anyone please tell me how I can free objects in C#? For example, I have an object:

Object obj1 = new Object();
//Some code using obj1
/*
Here I would l         


        
9条回答
  •  醉酒成梦
    2021-01-01 22:30

    You stop referencing them and let the garbage collector take them.

    When you want to free the object, add the following line:

    obj1 = null;

    The the garbage collector if free to delete the object (provided there are no other pointer to the object that keeps it alive.)

提交回复
热议问题