Re: object references



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
.



Relevant Pages

  • Re: Writing huge Sets() to disk
    ... pushes it's internal dictionaries ... > Almost anything you do copies references. ... > store the values on disc in a reasonably efficient manner. ... bsddb creaps on me that I can store as a key or value only a string. ...
    (comp.lang.python)
  • Re: Which database design is better
    ... you can update primary keys because you can ... of employee. ... Remember that part in the specs in this thread about each store ... then I can use a REFERENCES clause. ...
    (microsoft.public.sqlserver.programming)
  • Re: how to make two references to one string that stay refered to the same string reguardless of the
    ... > and have a conversion table to say that 12 translates into Monty Ville. ... Given that you've got to store "Monty Ville" somewhere, ... well just have several references to the same string. ... "Monty Ville" will be a reference to the same string object. ...
    (microsoft.public.dotnet.languages.csharp)
  • Inheritance, vectors and copy
    ... and two derived classes: ... the same references in v2 and v3, ... object in the vector and store the reference to the copy in v3. ... call a virtual self-copy method; ...
    (comp.lang.cpp)
  • Re: System.gc not enqueuing cleared WeakReferences
    ... all cleared WeakReferences will be enqueued, but this does not appear to ... In Sun's implementation all references get passed through a maximum priority thread before becoming enqueued. ... that all WeakReferences are actually enqueued? ...
    (comp.lang.java.programmer)