 Once no references to an object remain, the unreachable memory becomes eligible to be freed automatically by the garbage collector.Something similar to a memory leak may still occur if a programmer's code holds a reference to an object that is no longer needed, typically when objects that are no longer needed are stored in containers that are still in use.If methods for a non-existent object are called, a null pointer exception is thrown.