Last active
January 4, 2020 14:44
-
-
Save Kamilahsantos/c0bcd27d5e2d97fe1f7fefdcf02fb725 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainObjectLifeCycle { | |
public static void main(String[] args) { | |
LifeCycle lifeCycle = new LifeCycle(); | |
LifeCycle lc1 = new LifeCycle (); | |
lc1.name="Kamila"; | |
lifeCycle.lc4=lc1; | |
lc1= new LifeCycle(); | |
lc1.name="Kamila do segundo objeto"; | |
lifeCycle.lc5=lc1; | |
lc1=null; | |
//Aqui estamos referenciando um objeto que não está mais acessível para um objeto que está acessível. | |
//Realizando uma referência indireta,o GC não vai mais excluir estes objetos. | |
System.out.println("objetos="+LifeCycle.counter); | |
System.out.println(lifeCycle.lc4.name); | |
System.out.println(lifeCycle.lc5.name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment