How do I keep GenericTreeModel from leaking references?
Arjan Molena added a”leak_references” property to GenericTreeModel to turn this behavior off, but in his words, “Turning this feature off (default is on, the old behaviour) will always decrement the refcount on PyObjects. This will prevent memory/refcnt leaks from happening. The Model should ensure that objects which are used as iterators are not destroyed before the iterator is destroyed. This sounds a bit silly, but there are no other way, unless we get to know when a iterator is being removed…” If you turn off “leak_references” and don’t keep careful track of your nodes, you get a good old-fashioned segfault. One easy way to “ensure that objects which are used as iterators are not destroyed before the iterator is destroyed” is to have your model keep a dictionary or list of tree nodes so that a reference stays around until you explicitly delete it. (See FAQ 13.15 for another method of keeping track of node references.
Arjan Molena added a”leak_references” property to GenericTreeModel to turn this behavior off, but in his words, “Turning this feature off (default is on, the old behaviour) will always decrement the refcount on PyObjects. This will prevent memory/refcnt leaks from happening. The Model should ensure that objects which are used as iterators are not destroyed before the iterator is destroyed. This sounds a bit silly, but there are no other way, unless we get to know when a iterator is being removed…” If you turn off “leak_references” and don’t keep careful track of your nodes, you get a good old-fashioned segfault. One easy way to “ensure that objects which are used as iterators are not destroyed before the iterator is destroyed” is to have your model keep a dictionary or list of tree nodes so that a reference stays around until you explicitly delete it.