sorry, I misunderstood your problem.

I thought you were suggesting the object was stuck in the dictionary because it had been used as a key.

can you explain the workflow a bit more please.

It seems something like:
1) data block created
2) time passes
3) something uses data block, finding it by ID
4) something else uses data block, overlapping with earlier user (otherwise refs would fall to 1)
5) all things that could use that data block are stopped
6) data block is redundant and could be purged - why not just remove it?

I'm not sure I understand the transitions between block being created and available, block used and then block being redundant.

If this is a cache cleanup thing, why not have a LastUsed value on blocks and flush them once they are stale beyond a certain point, driven by a thread woken up every so often and only being active based on memory reaching a threshold?

Okay, I'll attempt it.

I have a dictionary set up for each possible kind of data block.

When part of my program requests a data block from the Database, it requests it by id. I pass my request first to my handling methods for the lookup dictionary, and if that data block has already been instantiated the dictionary will return a reference to that single instance. If it has not been instantiated yet, the handler method will create an instance and populate it's properties, and then store it in the lookup dictionary. It will then pass a reference to that data block back to the calling method.

All of the above works.

What happens though is that there is no way for me to remove the instance from the lookup dictionary once my program no longer requires a reference to it. It get's referenced once when I place it in the lookup dictionary, and then in increments every time I pass a reference to the instance off to another part of my program. It correctly decrements it's ref count once the parts of my program have finished manipulating it's data, and it falls back to a ref count of one when nothing is using it, because it is still referenced by it's holding lookup dictionary.

Therefore when it's ref count reaches one I'd like to remove it from my lookup dictionary, however there is no easy way to get an object.referenceCount value.

I could do it manually, by adding a refCount property to each data class, but I'd really rather not as it opens up too much potential for memory leaks.

I guess I'm just hoping there's a way to get an objects ref count that I've overlooked somewhere...

- Tom
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to