× 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.



An object gets destroyed (garbage collected) only when there is no reference
to it.  When one stores an object into a Map, the Map has a reference to it.
To destroy this object one has to remove this entry from Map in addition to
setting other references to null.

It will be interesting to know how WeakHashMap works.



Bruce



----- Original Message -----
From: "Mike Silvers" <msilvers@HBS-INC.COM>
To: <java400-l@midrange.com>
Sent: Thursday, November 14, 2002 12:14 PM
Subject: Re: destroy() method V.S. finalize() method


>
> I see an additional method as unnecessary overhead for the applications
> programmer, if I can do what I am trying to do here.  I may have to resort
> to that method.  At first, I thought that setting the reference to null
will
> cause the object to be destroyed.  As I am looking into this a bit more, I
> am learning that simply setting an object to null will not destroy the
> object.  There was an interesting discussion of object creation and
> destruction in the Sun Java forums that explains allot here.
>
> Mike
>
>
> ----- Original Message -----
> From: "Mark Phippard" <MarkP@softlanding.com>
> To: <java400-l@midrange.com>
> Sent: Thursday, November 14, 2002 2:53 PM
> Subject: Re: destroy() method V.S. finalize() method
>
>
> > This is a multipart message in MIME format.
> > --
> > [ Picked text/plain from multipart/alternative ]
> > What is setting the reference to null?
> >
> > If it is being done in code, then why not just add a method to the
object
> > that you call to destroy it before setting it to null?
> >
> > Mark
> >
> >
> >
> >
> >
> > "Mike Silvers" <msilvers@HBS-INC.COM>
> > Sent by: java400-l-admin@midrange.com
> > 11/14/2002 02:54 PM
> > Please respond to java400-l
> >
> >
> >         To:     <java400-l@midrange.com>
> >         cc:
> >         Subject:        Re: destroy() method V.S. finalize() method
> >
> >
> > 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.
> > >
> > >
> >
> >
> > _______________________________________________
> > 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.
> >
> >
> >
> > _______________________________________________
> > 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.
> >
> >
>
>
> _______________________________________________
> 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 ...

Follow-Ups:
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.