Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear a memory early in c#

After finishing use the varible, can I clear the memory early before the GC do it?

like image 818
user496949 Avatar asked Nov 27 '22 18:11

user496949


1 Answers

If there are specific resources that need to be released immediately, implement the IDisposable interface and call Dispose() (sometimes Close() on some objects, such as streams).

If you are looking to prevent passwords being retained in memory beyond their lifespan, SecureString supports this, though it is not simple to use.

Otherwise, you have no control over when the garbage collector runs or what it actually does. If you desperately need this kind of control, you need a lower level language.

like image 103
Zooba Avatar answered Dec 17 '22 00:12

Zooba