Release resources in .Net C#

前端 未结 6 1518
庸人自扰
庸人自扰 2021-02-19 11:19

I\'m new to C# and .NET, ,and have been reading around about it.

I need to know why and when do I need to release resources? Doesn\'t the garbage collector take care of

6条回答
  •  故里飘歌
    2021-02-19 11:51

    The garbage collector releases MEMORY and cleans up - through disposition - elemetns it removes. BUT: IT only does so when it has memory pressure.

    THis is seriously idiotic for ressources whree I may want to explicitely release them. Save to file, for example, is supposed to: Open the file, write out the data and - close the file, so it can be copied away by the user if he wants, WITHOUT waiting for the GC to come around and release the memory for the file object, which may not happen for hours.

提交回复
热议问题