Java has a garbage collector and that means it collects any objects or data that are not used anymore(i.e. there is no link to them anywhere) and deletes them automatically.