Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Garbage Collection

Reply
Thread Tools

Garbage Collection

 
 
Gordon Beaton
Guest
Posts: n/a
 
      05-28-2004
On Fri, 28 May 2004 10:10:48 +0200, Michael Borgwardt wrote:
> Very interesting detail. Then what can you do to reclaim the memory
> if you come to a point where you have instantiated a Thread but
> change your mind about running it? I can't seem to find anything in
> the Thread class that could be used to handle this case.


It seems you have to run it in that case. If you expect that you'll
create threads and later change your mind, you could always set a
field checked by the run method, then run the thread anyway:

public void run() {
if (!cancelled) {
...
}
}

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
 
xarax
Guest
Posts: n/a
 
      05-28-2004
"Roedy Green" <look-> wrote in message
news:...
> On Thu, 27 May 2004 11:58:52 +0200, Michael Borgwardt
> <> wrote or quoted :
>
> >It becomes *egligible* for garbage collection when its run() method
> >has finished executing. When it will actually *be* garbage collected
> >is up to the JVM to decide.

>
> Be careful. If you instantiate a Thread but never get around to
> calling the start method, it will hang around forever,
> even if you drop all references to it.
>
> see http://mindprod.com/jgloss/packratting.html


There is nothing the JavaDoc for Thread or ThreadGroup
that indicates that a JVM implementation is required
to hold an inactive Thread reference in the ThreadGroup.

When instantiating the Thread, there is nothing that
indicates that the Thread instance is referenced in the
ThreadGroup before the thread is started. The Thread
instance may hold a reference to the ThreadGroup to
which the thread will belong after the start() method
is called. The start() method could add the Thread
reference to the ThreadGroup at that time.

Your glossary is quite likely describing a particular
implementation detail that can change across different
JVM releases and almost certainly across different JVM
vendors.



 
Reply With Quote
 
 
 
 
Neal Gafter
Guest
Posts: n/a
 
      05-28-2004
Roedy Green wrote:
> Be careful. If you instantiate a Thread but never get around to
> calling the start method, it will hang around forever,
> even if you drop all references to it.


In fact, JDK 1.5.0 does not retain unstarted threads that otherwise become
unreachable. See <http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4089701>.

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-28-2004
On Fri, 28 May 2004 14:09:42 GMT, "xarax" <> wrote or
quoted :

>There is nothing the JavaDoc for Thread or ThreadGroup
>that indicates that a JVM implementation is required
>to hold an inactive Thread reference in the ThreadGroup.


Correct. But it does.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      05-28-2004
Roedy Green wrote:
> On Fri, 28 May 2004 14:09:42 GMT, "xarax" <> wrote or
> quoted :
>
> >There is nothing the JavaDoc for Thread or ThreadGroup
> >that indicates that a JVM implementation is required
> >to hold an inactive Thread reference in the ThreadGroup.

>
> Correct. But it does.


The conveniently missed point here is that this statement is meaningless
unless you define "it". If "it" is a Sun release of the JVM prior to
1.5, then you're right.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
Templates - Garbage In Garbage Not Out ramiro_b@yahoo.com C++ 1 07-25-2005 04:48 PM
Garbage Collection kamran MCSD 1 04-04-2005 10:04 PM
Garbage Collection and Manage Code? Laser Lu ASP .Net 5 01-27-2004 03:48 AM
Debbugging help! (.NET 1.1 Framework Garbage Collection Problems) Cheung, Jeffrey Jing-Yen ASP .Net 3 07-10-2003 07:29 PM



Advertisments