ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

How an object becomes eligible for Garbage Collections?

user-image
تم إضافة السؤال من قبل Ajith Fernandez , Software Engineer , Nayasoft Solutions Pvt.ltd
تاريخ النشر: 2013/12/03
Mohd shahnawaz khan
من قبل Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution

An object becomes eligible for Garbage collection or GC if its not reachable from any live threads or any static references in other words you can say that an object becomes eligible for garbage collection if its all references are null. Cyclic dependencies are not counted as reference so if Object A has reference of object B and object B has reference of Object A and they don't have any other live reference then both Objects A and B will be eligible for Garbage collection. Generally an object becomes eligible for garbage collection in Java on following cases: 1) All references of that object explicitly set to null e.g. object = null 2) Object is created inside a block and reference goes out scope once control exit that block. 3) Parent object set to null, if an object holds reference of another object and when you set container object's reference null, child or contained object automatically becomes eligible for garbage collection.

Huzefa chikhly
من قبل Huzefa chikhly , JAVA DEVELOPER , PRIMALINK SOLUTIONS INDIA PVT LTD

object becomes eligible for Garbage Collections when no any refrence point to that object. but in cyclic dependency where object A point object B and object B point object A it lead to memory leak and non of the object get garbage collected so this type of code is not recommended and its bad code. may be im wrong and mr Mohd shahnawaz is right but this is what i learn during my java training.

مستخدم محذوف‎
من قبل مستخدم محذوف‎

An object becomes eligible for garbage collection when the reference of that particular object is set to null, implicitly or explicitly, even though reference is set to null garbage collector will call "finalize()"  method on that object which is eligible for garbage collection, we can't say immediatly that object is garbage collected((destroyed) which is nothing but destruction phase).i hope u get my Point...

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟