In both cases, when the program finishes, all the memory used is reclaimed.
Memory leaks are most critical in programs which run for a very long time (days, weeks, months, years even).
solved How long does memory leak itself exist in C++ and how does an equivalent Java program differ? [duplicate]