Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Java

Reply
 
LinkBack Thread Tools Display Modes
Old 03-01-2005, 09:40 AM   #1 (permalink)
dancer
Registered User
 
Join Date: Mar 2005
Posts: 1
dancer is on a distinguished road
Question Is a Static Reference to an Object Garbage Collected?

If I declare a static reference to an object, will that reference remain in memory or will it eventually get garbage collected? I have a PropertyManager that has a static reference to a Properties object. This reference is set in the initialization process of the servlet after loading the Properties object from the property file. The PropertyManager is not a Singleton.

The code looks like this:

Class PropertyManager () {
private static Properties props = null;
}

public static void setProps(Properties props) {
PropertyManager.props = props;
}

In servlet:
FileInputStream fileConfig = new FileInputStream(servlet.getServletContext().getRea lPath(configFile));
Properties props = new Properties();
props.load(fileConfig);
PropertyManager.setProps(props);

When I try to reference the Properties object from other classes, will it still be there, or will it get garbage collected at some point? Do I have to declare this as a Singleton in order to keep it in the heap?

Any help would be appreciated!
dancer is offline   Reply With Quote
Old 03-01-2005, 10:50 AM   #2 (permalink)
jeffro
Person of interest
 
jeffro's Avatar
 
Join Date: Mar 2003
Location: New Jersey
Posts: 102
jeffro is on a distinguished road
It depends on the context where you are keeping a reference to PropertyManager. If you keep it in session, as long as the users session is valid it will be there. Other-wise if you create it then move on with out setting it to a context it is a prime candidate for GC.
__________________
Jeffro
Linux counter#:213782
GnuPG ID: 406238E7
jeffro is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On



All times are GMT -8. The time now is 11:13 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting