[Gtk-sharp-list] Gtk.ListStore IEnumerable Interface

Norbert Berzen norbert at spice.gia.rwth-aachen.de
Thu Jan 26 06:18:44 EST 2006


Hello people,

I'am doing a little spare time project with mono/gtk#. When using
'foreach' on a 'Gtk.ListStore' my program crashes. Digging into the
gtk#-implementation I get the following assumption about the reasons for
that crash:

The Method 'IEnumerable.GetEnumerator' simply constructs a
'TreeIterator' which connects 4 event handlers to the 'model' the
iterator operates on.

My guess is as follows: What will happen, when the 'TreeEnumerator'
ceases to exist after completion of the 'foreach'-loop and then the
'TreeModel' gets changed?

As of my understanding the 'TreeModel' will call the handler(s)
'row_changed', 'row_inserted', (or whatever) on the no longer existing
'TreeEnumerator' and that leads to a crash.

One may argue that alas the 'TreeModel' exists the 'TreeEnumerator' will
not get reaped (by GC) since the 'TreeEnumerator' is reachable through
the 'TreeModel's' event. But that may not be true since the
'TreeModel's' event is no field-like event! Instead of this it is
declared by an 'event accessor' declaration
(see .../gtk/generated/ListStore.cs). So there may be no GC-visible
reference to the 'TreeEnumerator'.

Can any of you prove my guesses?

If my assumptions are correct, could it be fixed by implementing a
finalizer '~TreeEnumerator' as follows?

~TreeEnumerator ()
{			
  model.RowChanged -= new RowChangedHandler (row_changed);
  model.RowDeleted -= new RowDeletedHandler (row_deleted);
  model.RowInserted -= new RowInsertedHandler (row_inserted);
  model.RowsReordered -= new RowsReorderedHandler (rows_reordered);
}


Thanks in advance,
-- 
Dr. Norbert Berzen              Tel.:   +49 241 80-95292
Geodaet. Institut, RWTH Aachen  Fax.:   +49 241 80-92142
Templergraben 55, 52062 Aachen  E-Mail: norbert at spice.gia.rwth-aachen.de


More information about the Gtk-sharp-list mailing list