Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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

user-image
Question ajoutée par mohammed ghufran , Senior Software Engineer , Vinculum Group Ltd (DP WORLD
Date de publication: 2018/03/25
Prajakta Naikare
par 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
par 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
par 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
par 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
par Ashkan Keshavarzi , Senior Java developer , PeykAsa

When the scope of this variable definition is reach to end

Radhwane Fellahi
par 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
par Partha Sarathi Ghosh , Developer

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

syed faheem uddin
par syed faheem uddin , Trainer , Qedge technology Pvt LTD

garbage collected will be "ABCD".

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?