For a remoting framework, I need to keep some metadata about object that I’m returning.
I have no control over the object themselves (so I can’t make them IDisposable), I also don’t know their type. my only assumption is that it’s a reference type.
The problem is life time, when do I free my metadata.
I intend to create a static dictionary(ConcurrentDictionary) and hold there a WeakReference to the object, and the metadata. The question is, how do i know when to delete the metadata?
is there a way to receive a notification when the object itself is finalized?
Also i don’t care about necromancy (object resurrection)
Thank you
If you’re using .NET4 or later you could possibly use
ConditionalWeakTable<K,V>.This would mean that you (probably) wouldn’t need to worry about freeing-up the metadata yourself: it would just disappear from the table once the object itself was gone.