• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt regarding Heap area of Java  RSS feed

 
Manu Somasekhar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I know that java heap contain a younger and older generation. The younger generation is divided into Eden space, survivor 0 and survivor 1.
My doubt is,
1. What is the advantage of having such areas instead of having one single heap space ?
2. If a minor garbage collection occurs in Eden space, a garbage object is moved to survivor 0. Why to move a garbage object to the subsequent space instead of removing from memory?

Any Help is appreciated.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manu Somasekhar wrote:1. What is the advantage of having such areas instead of having one single heap space ?
2. If a minor garbage collection occurs in Eden space, a garbage object is moved to survivor 0. Why to move a garbage object to the subsequent space instead of removing from memory?

Simple answer: Don't know. - And, in 12 years of using Java, I've never had to worry about it.

I'm not even sure what you mean by a "minor" garbage collection (although I have no doubt that such an animal might exist).

If I was to take a guess, I'd venture that there is some advantage to the gc to know when created objects have survived a removal action, and that it's therefore worth moving them to an area that makes this obvious (maybe also to make room for new objects to be created).

However, it's pure speculation; and unless I decide to write a gc myself I don't think I'll be worrying about it anytime soon.

Do you plan to? Because if not, I'd say it comes under the heading of DontSweatIt.

Winston
 
Manu Somasekhar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Winston. That was very helpful.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manu Somasekhar wrote:Thanks Winston. That was very helpful.

You're most welcome.

I should add that it's just my opinion. And there's nothing wrong with intellectual curiosity.

Winston
 
Manu Somasekhar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Manu Somasekhar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a mistake in my question.
Manu Somasekhar wrote:
2. If a minor garbage collection occurs in Eden space, a garbage object is moved to survivor 0.

This is wrong. In fact, during minor GC a dirty object is copied from one heap area to another if it is still in use. The reason for dividing heap memory may be(I am not sure ) the following.

Different objects may have different life spans. So placing them in a single heap space and running GC may not be an efficient idea. Instead, the heap is divided into segments and different GC algorithms with different execution costs are applied to each segments.

Please correct me if I am wrong.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manu Somasekhar wrote:Please correct me if I am wrong.

Again, pure speculation: A space called "Eden" sounds to me like it's an area that contains newly created objects.

I'm not sure how things are done these days, but one of the reasons that some of memory is called "heap" memory is that it is (or used to be) managed as a Heap.

So:
If I want to be able to clear this area quickly (in order to provide space for new objects), maybe I need something like a "quick collection" that simply checks THAT area and removes any object that needs removing. Presumably, there will also be a module that actually creates objects as well, and If this area is NOT arranged as a Heap (quicker), then unless it is supposed to deal with "gaps" then it might be easier to leave survivors of a "quick" clearance in place.

However, as already stated: pure speculation. I have no idea if I'm actually correct.

Winston
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!