How do i free objects in C#

后端 未结 9 1726
傲寒
傲寒 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

    As others have mentioned you don't need to explicitly free them; however something that hasn't been mentioned is that whilst it is true the inbuilt garbage collector will free them for you, there is no guarantee of WHEN the garbage collector will free it.

    All you know is that when it has fallen out of scope it CAN be cleaned up by the GC and at some stage will be.

提交回复
热议问题