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

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

متابعة

Core java basic String s=new String("ABCD"); s="XYZ"; when s will be garbage collected ?

user-image
تم إضافة السؤال من قبل mohammed ghufran , Senior SoftwareEngineer , DP World Asia Holding Ltd
تاريخ النشر: 2018/03/25
Prajakta Naikare
من قبل Prajakta Naikare , Senior Software Developer , Redknee India Pvt Ltd.

There are two conditions under which S will be garbage collected.

1. If S is assigned to null value during the course of application lifetime and after that S is never being reassigned to any other value.

2. When the application terminates JVM shutdown then S will be garbage collected if S is never being assigned to null value. 

PUSKAR KUMAR
من قبل PUSKAR KUMAR , Software Applications Developer , InetSolv technology

now s pointing to "xyz" object so run time "ABCD" removed by garbage collector

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

When the string "XYZ" will be assigned to s. the old s string object will be unreachable which means it is a garbage collected.

yahia dekar
من قبل yahia dekar , it engineer , university of sidi bel abbes

s he terminated when the program  he not need him  it s dynamically by jvm

amit kumar  pandey
من قبل amit kumar pandey , PHP Developer , technobrix

when assign s="XYZ";

then reference of creating object of string by using 'new' keyword will be garbage collected 

Ashkan Keshavarzi
من قبل Ashkan Keshavarzi , Senior Java developer , PeykAsa

When the scope of this variable definition is reach to end

Radhwane Fellahi
من قبل Radhwane Fellahi , Software Engineer , ENAGEO SONATRACH

When there are no more references to that object or when the variable goes out of scope.

Partha Sarathi Ghosh
من قبل Partha Sarathi Ghosh , Developer

When the scope of the String s ends, or at the end of the program.

syed faheem uddin
من قبل syed faheem uddin , plant supervisor , Africa snacks

garbage collected will be "ABCD".

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