How java takes out the Garbage?

  1. Each time an object is created in java, it goes into an area of memory known as The Heap. ( Heap –  heap is an area of pre-reserved computer main storage ( memory ) that a program process can use to store data in some variable amount that won’t be known until the program is running.)
  2. All Objects – no matter when , where, or how they’re created – live on the the Heap.
  3. But its not just any old memory heap; the Java heap is actually called the Garbage-Collectible heap.
  4. When you create an Object, Java Allocates memory space on the heap according how much that particular object needs.
  5. An Object with say , 15 instance variables, will probably need more space than an Object with only two instance variables.
  6. But what happens when you need to reclaim the space ? How do you get an object out of the heap when you’re done with it ? Java manages that memory for you! when the JVM can ‘see’ that an Object can never be used again, that object become eligible for garbage Collection.
  7. And if you’re running low on memory, the Garbage Collector will run, throw out the unreachable objects, and free up the space, so that the space can be reused.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s