 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
| • |
But!
This is not a destructor.
|
|
| • |
Java
objects do not always get garbage collected –
|
|
| • |
The
garbage collector is only run after all references to an object
|
|
|
have
been released and memory is insufficient (or running low). It
|
|
|
may
just automatically return the memory to the operator system after
|
|
execution!
|
|
|
– |
So,
use finalize() for releasing memory that the garbage collector cannot
|
|
|
predict,
but you may need to explicitly cause the garbage collector to be
|
|
|
exeucted:
System.gc()
|
|
| • |
Bottom
line, finalize() cannot be relied upon.
|
|
| • |
Even
functions that look like they should cause finalize to be used are
|
|
|
problematic
and at times buggy. Its invokation is not guaranteed!
|
|