Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Memory

 
pradeep chellappan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
Pradeep
 
Campbell Ritchie
Sheriff
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic