Garbage Collection on one object, C#

前端 未结 6 1125
时光说笑
时光说笑 2021-01-13 22:11

I need to dispose of an object so it can release everything it owns, but it doesn\'t implement the IDisposable so I can\'t use it in a using block. How can I make the garbag

6条回答
  •  孤城傲影
    2021-01-13 22:24

    Garbage collection in .NET is non deterministic, meaning you can't really control when it happens. You can suggest, but that doesn't mean it will listen.

    Tells us a little bit more about the object and why you want to do this. We can make some suggestions based off of that. Code always helps. And depending on the object, there might be a Close method or something similar. Maybe the useage is to call that. If there is no Close or Dispose type of method, you probably don't want to rely on that object, as you will probably get memory leaks if in fact it does contain resourses which will need to be released.

提交回复
热议问题