my dog learned polymorphism
The moose likes Beginning Java and the fly likes Memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Memory" Watch "Memory" New topic


pradeep chellappan

Joined: Oct 20, 2005
Posts: 29
Hi all,

Can anyone please explain me what is the difference between cleaning up memory and releasing memory with a simple example.I hope that this doubt of mine will be useful for many!

Advance Thanks!
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46383
Is there a difference? Cleaning up memory and releasing memory are things you don't do; Java does memory management automatically. So just forget about it.

There are a few instances where you might have to take precautions to prevent a memory leak, one being opening a file for reading. You have to put the .close() call inside a finally block to make absolutely sure that the file is closed, even if you have an Exception.

If you go to the Java website and put "memory management" into "search," you get this.
ak pillai
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
I guess they mean the same thing. Unless some one can clarify otherwise.

The Java Garbage Collector runs in a low priority thread and it cannot be forced to execute. So in your code you can provide clean up methods to make sure that your objects are eligible for garbage collection once you are finished with those objects. This does not mean that your memory will be immediately released.

Your memory would not be released until the Garbage Collection starts to run to free up your memory.

java j2ee job interview questions with answers | Learn the core concepts and the key areas
I agree. Here's the link:
subject: Memory
It's not a secret anymore!