Manually destroy C# objects

前端 未结 8 2269
感动是毒
感动是毒 2020-11-29 06:28

I am fairly new to learning C# (from Java & C++ background) and I have a question about manual garbage disposal: is it even possible to manually destroy an object in C#?

8条回答
  •  长情又很酷
    2020-11-29 06:50

    You can force the garbage collector to run after the variable you want to destroy goes out of scope, but you normally don't want to do that, as the garbage collector is more efficient if left to do its own work.

    Forcing garbage collection can be done with GC.Collect, but don't do it. In my 10 years as a .NET developer, I have never needed it.

提交回复
热议问题