[Gtk-sharp-list] IDisposable
Paolo Molaro
lupus@ximian.com
Wed, 4 Sep 2002 20:13:19 +0200
On 09/04/02 adam treat wrote:
> Ok, we tried to have the Dispose method unregister the objects in the hash, but there was a
> problem with Monitor locking and the GC:
>
> ~Pixbuf ()
> {
> Dispose ();
> }
>
> Dispose ()
> {
> UnregisterObject ();
> }
>
> This should work, but when the program thread tries to access the hash for introspection and the
> GC also tries to access the hash, the program freezes, regardless whether it is lock()ed in both
> threads.
If a GC happens while adding an object to the hash (and so the hash is
locked) an object may be finalized (and hence it may need to be removed
from the hash) resulting in a deadlock. I don't know if an alarm is
supposed to fire also in this case to get the finalizer killed
(like it should happen at program termination).
If we implement the finalize timeout, you'll get stale references in the
hash (and an ugly temporary freeze of the application: this can be
avoided running the finalizers in a separate thread).
lupus
--
-----------------------------------------------------------------
lupus@debian.org debian/rules
lupus@ximian.com Monkeys do it better