Skip to content

Instantly share code, notes, and snippets.

@Kamilahsantos
Last active January 4, 2020 14:44
Show Gist options
  • Save Kamilahsantos/c0bcd27d5e2d97fe1f7fefdcf02fb725 to your computer and use it in GitHub Desktop.
Save Kamilahsantos/c0bcd27d5e2d97fe1f7fefdcf02fb725 to your computer and use it in GitHub Desktop.
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