[Panel-devel] Problem with caching applet backgrounds
Peter Penz
peter.penz at gmx.at
Sun Jul 29 17:57:15 CEST 2007
Hi Thomas,
On Sunday 29 July 2007 17:20:59 Thomas Georgiou wrote:
> On Sunday 29 July 2007 01:02:03 am Aaron J. Seigo wrote:
> > * there's no need to new() pixmaps. it leads to memory leaks, such as how
> > you're leaking backgroundPixmap.
>
> Wouldn't the pixmap be deleted after the function returns though?
I think Aaron refers to the line:
[A] QPixmap* backgroundPixmap = new QPixmap(leftWidth + contentWidth +
rightWidth, topHeight + contentHeight + bottomHeight);
which should be written like:
[B] QPixmap backgroundPixmap(leftWidth + contentWidth + rightWidth, topHeight
+ contentHeight + bottomHeight);
In the case of [A] the pixmap is allocated on the heap and not deleted until
you invoke 'delete backgroundPixmap' (which seems is not done).
In the case of [B] the pixmap is allocated on the stack [1] and destructed
automatically as soon as the end of the scope is reached.
I found an interesting discussion about stack vs. heap here :-)
http://discuss.joelonsoftware.com/default.asp?joel.3.103986.24
Best regards,
Peter
[1] To be more exact: The Pixmap instance will be allocated on the stack, but
the data of the pixmap will be allocated on the heap and freed as soon as the
destructor gets invoked.
> And should i store it as a pointer or by value in the d-pointer?
>
> Thomas Georgiou
> _______________________________________________
> Panel-devel mailing list
> Panel-devel at kde.org
> https://mail.kde.org/mailman/listinfo/panel-devel
More information about the Panel-devel
mailing list