Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient Garbage Collection

Consider the following object

class someObject;
{
   public objectA A{get;set;}
   public objectB B{get;set;}
   public objectC C{get;set;}
   public objectD D{get;set;}
   //...
}

at some point ObjectD is not needed anymore but the Instance of someObject still exist and will do so for couple hours, objectD takes up alot of memory so after its role is done i did set it up to null.

  • does that mean the memory will get freed from ObjectD as soon as i set it to null?
  • if an object sets for so long unused in some scope what does .NET do about it?
like image 684
FPGA Avatar asked Apr 24 '26 22:04

FPGA


1 Answers

does that mean the memory will get freed from ObjectD as soon as I set it to null?

It's not object sets to null - its reference to object in memory sets to null. And object will exist until Garbage Collector will collect it (if you don't have any other references to this object).

Take a look on Fundamentals of Garbage Collection

like image 183
Sergey Berezovskiy Avatar answered Apr 27 '26 12:04

Sergey Berezovskiy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!