473,381 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 software developers and data experts.

object references

Hi,

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?

Thx in advance

Frederik
Dec 4 '05 #1
3 1420
Frederik Vanderhaegen <fr*******************@pandora.be> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 4 '05 #2
Frederik Vanderhaegen wrote:
Hi,

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?


Look up the WeakReference class, it might be able to help you.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Dec 4 '05 #3

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Frederik Vanderhaegen <fr*******************@pandora.be> 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.


"Periodically" is the sticky part. I've been meaning to write a C#
replacement for Java's WeakHashMap, but haven't had the time to do
performance evaluation of the various choices: Check every N accesses, check
every N adds, check every N seconds, check only the current hash chain vs.
the whole map, etc.

It's a shame .NET doesn't have an analogue of Java's ReferenceQueues (i.e.
notifications when a weak reference no longer refers.)
Dec 4 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris S. | last post by:
I'm trying to make a graphical editor and browser for Pickled files. One aspect I'm not sure about is how to detect multiple references to the same data. For instance, say I had the Pickled...
4
by: Mark D. Anderson | last post by:
About a month ago Richard Cornford did an interesting analysis of a memory leak in jscript (internet explorer) when there are "circular" references between DOM objects and (real) jscript objects:...
44
by: Steven T. Hatton | last post by:
This may seem like such a simple question, I should be embarrassed to ask it. The FAQ says an object is "A region of storage with associated semantics." OK, what exactly is meant by "associated...
3
by: RobG | last post by:
I am playing with a script that will allow columns of a table to be moved by dragging them left or right. To do this with functions is fairly straight forward, however after looking at Richard...
5
by: Robert Zurer | last post by:
I have a large pool of business objects all referencing one another in various ways. In the client application I want to do something like employee.Delete(); Behind the scenes, I want to...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
28
by: Stef Mientki | last post by:
hello, I'm trying to build a simple functional simulator for JAL (a Pascal-like language for PICs). My first action is to translate the JAL code into Python code. The reason for this approach is...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.