Garbage collection in java is a low priority thread that run's automatically.It run and destroy the objects that are not being referred to any variable.
We can request to run the garbage collector using System.gc(); but it is not guaranteed that it is request will full fill.
ex-
The ab in line 4 now eligible for garbage collection in these line code automatically by garbage collector.