Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28
  1. #21
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    Quote Originally Posted by Junky View Post
    Rule #1 of Garbage Collection: forget about it!
    This. I think Java programming teachers are somewhat obsessed with it because it is (or was) a novel feature of the language. But they do their students a disservice by mentioning it at all. Beginner Java programmers have absolutely no reason to even know the GC exists, much less concern themselves with what it's doing.

    I almost went off on a rant about this in an earlier comment. I'm still restraining myself on the subject of bad teachers...
    Get in the habit of using standard Java naming conventions!

  2. #22
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by kjkrum View Post
    This. I think Java programming teachers are somewhat obsessed with it because it is (or was) a novel feature of the language.
    Lisp (1959) already had a complete garbage collector.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #23
    giorgi is offline Member
    Join Date
    Apr 2011
    Posts
    23
    Rep Power
    0

    Default

    guys i accept that tips about GC.but our teacher gave us that exercise for Tuesday,and i want to be a good student and answer it.otherwise he will reply that exercise on Tuesday.and when he replies that exercise i will write it here.

    new to java
    Giorgi

  4. #24
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by giorgi View Post
    guys i accept that tips about GC.but our teacher gave us that exercise for Tuesday,and i want to be a good student and answer it.otherwise he will reply that exercise on Tuesday.and when he replies that exercise i will write it here.
    Hint: just before an object is garbage collected its void finalize() method is called. Increment a (static?) counter in the constructor and decrement it again in the finalize() method. Note that if the JVM exits it is not garanteed that the finalize() methods are called.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #25
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    I think (and it's been a while since I looked into this, so it may have changed) that things are only stuck in the finalization queue if they have implemented finalize(). Consequently it doesn't happen for all objects. They're a special case.
    And, as I said earlier, it only tells you that the object is now eligible for garbage collection, since the gc will (after running finalize()) simply stick the object in the pile of stuff for the normal gc routine to clear up.

    So that counter will represent things that are live, plus things that are in the finalization queue, but there may also be things that haven't been collected yet.

  6. #26
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Tolls View Post
    I think (and it's been a while since I looked into this, so it may have changed) that things are only stuck in the finalization queue if they have implemented finalize(). Consequently it doesn't happen for all objects. They're a special case.
    And, as I said earlier, it only tells you that the object is now eligible for garbage collection, since the gc will (after running finalize()) simply stick the object in the pile of stuff for the normal gc routine to clear up.

    So that counter will represent things that are live, plus things that are in the finalization queue, but there may also be things that haven't been collected yet.
    Yep, all true, but that's why I wrote:

    Quote Originally Posted by The Magnificent
    Hint: just before an object is garbage collected its void finalize() method is called.
    (boldfacing is mine) The trouble is that we don't know when an object is garbage collected and when the finalizer() is registered somewhere in a gc queue, but it's as close as we can go ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #27
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    "The Magnificent"?
    :D

  8. #28
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Tolls View Post
    "The Magnificent"?
    :D
    Yep, that's my middle name, why ask? ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Page 2 of 2 FirstFirst 12

Similar Threads

  1. about garbage collector
    By sudharani in forum New To Java
    Replies: 1
    Last Post: 04-25-2011, 11:25 AM
  2. Garbage Collector tuning
    By javaOrC in forum Advanced Java
    Replies: 45
    Last Post: 03-02-2011, 11:51 PM
  3. In defense of the Garbage Collector
    By Katanagas in forum Advanced Java
    Replies: 2
    Last Post: 10-25-2010, 06:40 PM
  4. Q about Garbage Collector
    By m00nchile in forum New To Java
    Replies: 4
    Last Post: 02-05-2010, 05:57 AM
  5. Garbage Collector and finalize()
    By arefeh in forum New To Java
    Replies: 5
    Last Post: 01-09-2010, 09:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •