Thank you for your answer.
Thats want I thought.
> Thank you for your answer.
>
[quoted text clipped - 11 lines]
>> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
>> Please reply only to the newsgroup.
I'm not sure if this is applicable, but if you control the objects being
garbage collected, you could add a finalizer who would notify some method
that it is about to get garbage collected. The garbage collector calls
the finalizer before collecting it unless the objects finalizer is
suppressed (typically in the Dispose method).

Signature
Happy Coding!
Morten Wennevik [C# MVP]
Tigger - 23 Oct 2006 08:45 GMT
My solution was to check if the weak reference had lost its target to
the GC before returning it.
I also implemented a timed process which purged items that had been
GCed.
Tigger
> > Thank you for your answer.
> >
[quoted text clipped - 17 lines]
> the finalizer before collecting it unless the objects finalizer is
> suppressed (typically in the Dispose method).
virtualwarp - 26 Oct 2006 21:49 GMT
Thank you for your answer.
I have already seen some examples on the net, they all make use of timers.
The problem with these solutions is that there is no collection containing
the GCed objects and I have to iterate through the whole list of
weakreferences. When you are dealing with long lists this isn't very fast. I
would prefere to setup something like a GC listener. In Java there is a
ReferenceQueue which is bound to several references. Whenever a weak
reference is set to null, ot is added to the queue. Since the queue contains
only the references pointing which objects where GCed. You can simple removed
them from your key list.
> My solution was to check if the weak reference had lost its target to
> the GC before returning it.
[quoted text clipped - 25 lines]
> > the finalizer before collecting it unless the objects finalizer is
> > suppressed (typically in the Dispose method).
virtualwarp - 26 Oct 2006 21:54 GMT
I already thought about this solution, but as you mentioned the object have
to be under my control and wouldn't rely on this.
> > Thank you for your answer.
> >
[quoted text clipped - 17 lines]
> the finalizer before collecting it unless the objects finalizer is
> suppressed (typically in the Dispose method).