🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8142

Garbage collecting and Singleton class's

#8142
From: Calvin R. Smith
Date: Fri, 20 Apr 2001 21:01
28 lines
1524 bytes
If I have a singleton class defined like the one below will it ever be
garbage collected after getInstance has been called or will the static
reference keep the object in memory forever?

public class Singleton
{
  private static Singleton singleton = null;

  private Singleton()
  {
    System.out.println("I've been created");
  }

  public synchronized static Singleton getInstance()
  {
    if (singleton == null)
    {
      singleton = new Singleton();
    }
    return singleton;
  }

  protected void finalize()
    throws Throwable
  {
    System.out.println("i've been finalized");
  }
}
Technical Details
Message-ID: <3ae0a428$1_2@dnews>
Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,b3b5ce7464e06d96,start
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-04-20 14:14:03 PST
Reply-To: "Calvin R. Smith" <calvinrsmith@hotmail.com>
From: "Calvin R. Smith" <calvinrsmith@hotmail.com>
Newsgroups: borland.public.jbuilder.java.language
Subject: Garbage collecting and Singleton class's
Date: Fri, 20 Apr 2001 15:01:57 -0600
Lines: 32
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Host: 207.201.104.111
Message-ID: <3ae0a428$1_2@dnews>
X-Trace: dnews 987800616 207.201.104.111 (20 Apr 2001 14:03:36 -0700)
Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews