I have referenced this link. Heap memory
I have a doubt
class Sample
{
public static void main(String[] args)
{
Date dt=new Date();
System.out.println(""+dt);
}
}
First dt will be at eden space if GC happens it will go to Survivor space , if GC happend when dt is in Survivor space (correct me if am wrong).
My Question is:
- if date is displayed and program completes the running process then will
these dt remains in Heap space ?? - If GC not occured where
dtwill remains ??
(eden space, survivor space or etc) - program completes the running process then dt will have no reference am i
right??
Thank you very much …..
if date is displayed(program completes the running process) will these dt remains in Heap space ??
(1) When the program completes there will be nothing on heap (dt will not exist)
If GC not occured where dt will remains ?? (eden space, survivor space or etc)
(2) All you can say about “dt” is that it will be created in eden space, After that if it goes to survivor space or Tenured Generation or gets garbage collected is all managed by GC and you cannot exactly know where it
program completes the running process dt will have no reference am i right??
(3) Yes it wont have any ref. In fact when the method terminates dt will be eligible for GC (now if gc happens rt away or takes time you don’t know)
To be clear, There are NO guarantees with GC, any memory allocated during program execution might remain allocated after program termination, in such cases it will be reclaimed by the operating system