aspose file tools*
The moose likes Java in General and the fly likes Why are people so worried about garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why are people so worried about garbage collection" Watch "Why are people so worried about garbage collection" New topic
Author

Why are people so worried about garbage collection

Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

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

Joined: Mar 17, 2011
Posts: 8014
    
  22

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


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

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

Joined: Aug 16, 2005
Posts: 14273
    
  21

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Oct 21, 2008
Posts: 1107

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

Joined: Oct 13, 2005
Posts: 39436
    
  28
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

Joined: Mar 17, 2011
Posts: 8014
    
  22

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

Joined: Oct 21, 2008
Posts: 1107

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

Joined: Mar 17, 2011
Posts: 8014
    
  22

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

Joined: Oct 13, 2005
Posts: 39436
    
  28
I use a FORTH implementation with null-terminated strings, which never throws seg-faults . . .


. . . but it happily gives segmentation errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why are people so worried about garbage collection