Resolve circular reference

Stefan Behnel stefan_ml at behnel.de
Tue Jan 11 02:47:26 EST 2011


moerchendiser2k3, 10.01.2011 22:19:
> On Jan 10, 7:18 pm, Stefan Behnel wrote:
>> moerchendiser2k3, 10.01.2011 18:55:
>>
>>>> If you can tell us why it's so important that the object be destroyed
>>>> at that given time, even while a reference to it exists, maybe we can
>>>> give you better suggestions.
>>
>>> Thanks for your answer! In my case the types A and B (in my example
>>> above)
>>> are a dialog and a dialog widget. At a special time I have to close
>>> and
>>> destroy all dialogs but this does not happen because the widget keeps
>>> the dialog alive. I have the reference to the dialog
>>> but after I closed the dialogs I also would like to destroy them
>>> because they have to free some special ressources.
>>
>> Objects within a reference cycle will eventually get cleaned up, just not
>> right away and not in a predictable order.
>>
>> If you need immediate cleanup, you should destroy the reference cycle
>> yourself, e.g. by removing the widgets from the dialog when closing it.
>>
>> Stefan
>
> The PyWidget type does not own the widget, it just points to it. I
> have an idea, would this fix the problem?
>
> I destroy the internal dictionary of the dialog which points to other
> PyObjects? Then I would cut the dependency.

Sure, that should work.

Stefan




More information about the Python-list mailing list