Re: object references
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Sun, 4 Dec 2005 12:42:19 -0000
Frederik Vanderhaegen <frederik.vanderhaegen@xxxxxxxxxx> wrote:
> I have created a datalayer which connect with a SQL-Server and in the
> datalayer I store the objects that are created in a static hashtable (for
> performance reasons) so I don't have to recreated the objects when I need
> them and I have then only one instance of that object in the memory.
>
> My problem is the following, the created objects are stored in the hashtable
> (when not yet present). After a certain time the hashtable becomes to big.
> Is there a way to find out when an object isn't used anymore by the
> application so I can delete it? In other words can I find out when an object
> stored in the hashtable has no more references to it?
You'd need to use WeakReferences - store the WeakReference in the table
instead of the real reference, and periodically check all the weak
references to see whether or not they're still alive, removing them if
not.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: object references
- From: Mike Schilling
- Re: object references
- References:
- object references
- From: Frederik Vanderhaegen
- object references
- Prev by Date: Re: Painting and zooming
- Next by Date: Re: object references
- Previous by thread: object references
- Next by thread: Re: object references
- Index(es):
Relevant Pages
|