Prevent that the GC frees the native GstIterator too early

The native GstIterator is freed once the Gst.Enumerable instance
is destroyed. At this point there could still be a Gst.Enumerator
instance that uses the native GstIterator and would crash then.

Store the Gst.Enumerable instance inside the Gst.Enumerator to
prevent the GC from destroying it before the enumerator is destroyed.
This commit is contained in:
Sebastian Dröge 2009-05-27 14:56:42 +02:00
parent febcfd772c
commit ede4562c23

View file

@ -7,6 +7,7 @@ namespace Gst {
internal class Enumerable : IEnumerable {
private class Enumerator : IEnumerator {
Enumerable enumerable;
Hashtable seen = new Hashtable ();
IntPtr iterator;
@ -57,7 +58,8 @@ namespace Gst {
gst_iterator_resync (iterator);
}
public Enumerator (IntPtr iterator) {
public Enumerator (Enumerable enumerable, IntPtr iterator) {
this.enumerable = enumerable;
this.iterator = iterator;
}
}
@ -67,11 +69,11 @@ namespace Gst {
public Enumerable (IntPtr iterator) {
this.iterator = iterator;
this.enumerator = new Enumerator (iterator);
this.enumerator = new Enumerator (this, iterator);
}
public IEnumerator GetEnumerator () {
return enumerator;
return this.enumerator;
}
~Enumerable () {