× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



David,

Here is what I am trying to accomplish:

I have an object with a unique number used in the construction of the
object.  I only want one instance of the particular object with that unique
reference number to be in memory.  There may be multiple ob the same type
object, but they all will have different unique numbers.

What I have done is created a HashMap.  I use the unique number as the key
(an Integer), and the object as the value.  When a new object is created,
the reference is placed in the HashMap (a static variable for this class).
What I need to do is when the object is destroyed (reference to null), I
need to remove the reference from the HashMap.

What I have done is placed code in the finalize() method to remove the
reference from the HashMap.  What I have found is that the finalize() method
is not being called.

I'll look into a WeakHashMap.

Mike

----- Original Message -----
From: "David Morris" <David.Morris@plumcreek.com>
To: <java400-l@midrange.com>
Sent: Thursday, November 14, 2002 2:32 PM
Subject: Re: destroy() method V.S. finalize() method


> Mike,
>
> I don't know what you are trying to accomplish and you say you
> "need to remove the object from a hashmap", but an alternative may
> be to use a WeakHashMap. Objects in a WeakHashMap can be
> garbage collected if there is no other reference.
>
> David Morris
>
> >>> msilvers@hbs-inc.com 11/14/02 10:51AM >>>
> I am creating a modification of the Singleton architecture.  I am only
> permitting one of a specific object with specific attributes.  When I
> am
> performing this function, I need to remove the object reference from a
> hashmap when the object is destroyed by the user.  My question is
> this....
> Should I place the code for removing the object reference from the
> hashmap
> in the destroy() method, or the finalize() method?
>
> My class is going to contain a static hashmap of objects with a key
> reference object.  I am concerned that either the destroy() or
> finalize()
> does not get called when a class is given a null reference.  I am
> thinking
> that one of the methods will get used for the last instance of the
> class and
> the other will be used for when each instance.
>
> any insights?
>
> Thanks
>
> Mike
> _______________________________________________
> This is the Java Programming on and around the iSeries / AS400 (JAVA400-L)
mailing list
> To post a message email: JAVA400-L@midrange.com
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/cgi-bin/listinfo/java400-l
> or email: JAVA400-L-request@midrange.com
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/java400-l.
>
>




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.