[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Keeping references to parent objects
From: Phil Thompson <phil () riverbankcomputing ! com>
Date: 2015-03-17 10:36:22
Message-ID: 13c0ef7118713d7b265bdfc85dcf540f () riverbankcomputing ! com
[Download RAW message or body]
On 17/03/2015 9:17 am, Florian Bruhin wrote:
> Hi,
>
> http://stackoverflow.com/a/11945184 says this:
>
> - A QObject should generally not have a reference to its parent or
> any of its ancestors (weak references are ok). This will cause
> memory leaks at best and occasional crashes as well.
>
> [...]
>
> - Objects that reference their parent or any ancestor can cause an
> exit crash.
>
> Is this true? Is there more information about this somewhere?
It's rubbish.
> I usually use signals, but there are some instances where it'd be
> useful if an object kept a reference to its parent. Should I use
> weakref for that everywhere?
No, just use an ordinary reference. An object keeps an internal
reference to the parent anyway, one more isn't going to make a
difference.
The only case where you might have problems is a QObject that is created
internally by Qt and then exposed through the API. It is missing the
plumbing used to detect if it gets deleted by C++. However those cases
are very rare.
Phil
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic