Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why are people so worried about garbage collection

 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an example question from this morning (or last night)
I would like to know when exactly the CachedRowSet is going to be eligible for GC.


my understanding is, if you can no longer get at it, it is eligable. So if you have lost it it is gone.

or is there something I am missing?
 
Winston Gutkowski
Bartender
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wendy Gibbons wrote:Here is an example question from this morning (or last night)
I would like to know when exactly the CachedRowSet is going to be eligible for GC.
my understanding is, if you can no longer get at it, it is eligable. So if you have lost it it is gone.
or is there something I am missing?

Personally I only worry about it when they go on strike.

But seriously, my guess is that people are worried about the word "cached" in the class name. In theory, it might be possible for such a class to create a collection behind the scenes that holds on to all references of "cached" rows; although if I designed something like that, I'd be sure to put it in 60-point type in the documentation.

I guess my questions would be:
1. Did the questioner have concrete evidence that objects were being retained long after they were supposedly "dead"?
2. Did s/he have specific evidence that they were CachedRowSet's?

Winston

 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this instance they were worried about sessions etc.

and maybe the word cache was worrying them.

just checking my own sanity really, that this isn't actually important knowledge?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15362
39
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Questions about when objects are eligible for garbage collection are also frequently asked by people studying for a certification exam, because they (think they) need to know this for the exam.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wendy Gibbons wrote:Here is an example question from this morning (or last night)
I would like to know when exactly the CachedRowSet is going to be eligible for GC.


my understanding is, if you can no longer get at it, it is eligable. So if you have lost it it is gone.

or is there something I am missing?


That pretty well sums it up.

In addition to the cert exams mentioned, I think a lot of people worry that since they don't have direct control over it, either a) It will go away when they still need it, or b) It will stick around after they're done with it, becoming a "leak". I think it's perfectly natural to want to understand the detailed rules about when something can be GCed. (And I suspsect it's not taught very well in beginner courses.)
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember coming from 'C' it was a lot to let go off, remembering your dealloc was almost the most important part of the code, users seemed to be able to live with the results being wrong, but not their server crashing.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But now you’re on Java™, you have to forget all about C. I have seen lots of errors because people forgot C/C++ and Java™ are so different.
 
Winston Gutkowski
Bartender
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wendy Gibbons wrote:I remember coming from 'C' it was a lot to let go off, remembering your dealloc was almost the most important part of the code, users seemed to be able to live with the results being wrong, but not their server crashing.

Ah, another C-ite. Weirdly enough, I found Java very liberating in that respect - no more memory-management code reviews. Bliss. Nirvana.

Of course you can't use pointers to mash huge tracks of memory in the blink of an eye, but after 11 years I'm kind of coming around to the idea that maybe that's not such a bad thing either.

Winston

(edit) I forgot the best thing of course: No more &#@*%! null-terminated strings. How many programs have gone TU because of that little gem?
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
Wendy Gibbons wrote:I remember coming from 'C' it was a lot to let go off, remembering your dealloc was almost the most important part of the code, users seemed to be able to live with the results being wrong, but not their server crashing.

Ah, another C-ite. Weirdly enough, I found Java very liberating in that respect - no more memory-management code reviews. Bliss. Nirvana.

Of course you can't use pointers to mash huge tracks of memory in the blink of an eye, but after 11 years I'm kind of coming around to the idea that maybe that's not such a bad thing either.

Winston

oh yes once you trust the jvm and let go, it is liberating, wonderful in fact.
 
Winston Gutkowski
Bartender
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wendy Gibbons wrote:oh yes once you trust the jvm and let go, it is liberating, wonderful in fact.

Did you spend as much time as I did looking for inexplicable segmentation faults? Such a wonderful error... (see 'null-terminated string' addition above).

Winston
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use a FORTH implementation with null-terminated strings, which never throws seg-faults . . .


. . . but it happily gives segmentation errors
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic