Results 1 to 3 of 3

Thread: garbage collection anonymous objects?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default garbage collection anonymous objects?

    Here's a weird thought. If I create an anonymous object then put that
    object to some use, could it still be garbage collected? In particular,
    given the following code, I don't see what guarantees that the thread
    created won't be garbage collected.

    Qt Code:
    1. public class ServerTest implements Runnable
    2. {
    3. public static void main(String[] args)
    4. {
    5. new Thread( new ServerTest() ).start();
    6. }
    7.  
    8. public void run()
    9. {
    10. while( true )
    11. { //....
    12. }
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    I didn't run this so sorry for any missed errors, but you get the idea.
    Shouldn't the JVM garbage collect the thread at some point? This code
    seems like trouble waiting to happen, but I'm sure I've seen this exact
    idiom elsewhere.
    Last edited by d_stranz; 31st July 2025 at 16:59.

Similar Threads

  1. Qt closeevent and garbage collection
    By ehnuh in forum Qt Programming
    Replies: 5
    Last Post: 2nd November 2012, 17:36
  2. QList and garbage collection
    By zgulser in forum Qt Programming
    Replies: 3
    Last Post: 5th April 2012, 15:38
  3. Garbage collection
    By Septi in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2010, 15:13
  4. QString, QStringList and garbage collection...
    By PaladinKnight in forum Newbie
    Replies: 4
    Last Post: 5th April 2010, 17:22
  5. question about garbage collection
    By Dumbledore in forum Qt Programming
    Replies: 4
    Last Post: 18th December 2007, 23:08

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.