Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

object referencing static member garbage disposal

Hope you don't mind, I may be missing something; I just need some clarification for the following scenario: If an object a contains a reference to a static list and also an entry in that static list, and object a falls out of scope, will it be garbage collected? Do I need to set object a's reference to the static list and reference to the entry in that list to null before it becomes eligible?

I understand that the static list contains objects which will live for the lifetime of the application, so I was thinking since object a still references an entry in that static list, it is still in the main dependency object graph of objects which are still live?

Thanks in advance

like image 857
Zivka Avatar asked Dec 04 '25 12:12

Zivka


1 Answers

In your case static list will live but a will be garbage collected becuase you cannot access it from any other place and there is no sense to keep it in memory. You don't need to null refference to static list.

like image 129
petro.sidlovskyy Avatar answered Dec 06 '25 02:12

petro.sidlovskyy



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!