[Interest] Memory leak

Alex Malyushytskyy alexmalvtk at gmail.com
Tue Jun 30 00:09:21 CEST 2015


  Widget may be deleting itself when closed (for example if
Qt::WA_DeleteOnClose
<qthelp://com.trolltech.qt.486/qdoc/qt.html#WidgetAttribute-enum> flag
is set ) which would be perfectly fine cool staff actually shows the widget
one or another way.

when
std::shared_ptr<Widget > temp( new Widget () );

does not make any sense unless widget is modal and exec() is called in the
same function.


On Fri, Jun 12, 2015 at 7:02 AM, Igor Mironchik <igor.mironchik at gmail.com>
wrote:

>  And to avoid memory leak just give to the Widget the parent. And when
> parent will die he will delete your Widget. It's just as example...
>
> But to answer to your question more clearly we need to know some more
> details. Such as what widget is doing, when he should die, and so on...
>
>
> On 12.06.2015 16:57, Dmitry Volosnykh wrote:
>
> In your case the 'temp' object will be deleted upon quitting function
> foo(), so the signalTriggered() is never emitted. In previous version, it
> would have been living longer because of memory leak you mentioned.
>
> On Fri, Jun 12, 2015 at 4:52 PM, Berkay Elbir <berkayelbir at gmail.com>
> wrote:
>
>>
>>  Hello all;
>>
>> We recently joined a new project, which is full with idiom like: ,
>>
>> void foo(){
>>     Widget* temp = new Widget;
>>     connect(temp, &Widget::signalTriggerred,[this, temp ]()
>>     {
>>          do cool staff...
>>     }}
>>
>> As you can see no delete nothing, I am afraid even user class "Widget" is
>> inherited QObject, this is still a leak. Does QT do something fancy to
>> prevent leek in case above?
>>
>> What I am planning to do:
>>
>> void foo {
>>      std::shared_ptr<Widget > temp( new Widget () );
>>      connect(temp.get(), &Widget::signalTriggerred,[this, temp] ()
>>      {
>>           do even cooler things...
>>      }}
>>
>> Is there a problem with my apporach? (For example I didn't want to use
>> .get() but compiler errors forced me to use it).
>>
>> Thanks in advance,
>>
>> BE
>>
>>
>>
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
>
>
> _______________________________________________
> Interest mailing listInterest at qt-project.orghttp://lists.qt-project.org/mailman/listinfo/interest
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150629/fc14fa05/attachment.html>


More information about the Interest mailing list