[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: QHash: two questions concerning memleak and key type
From: Frank Reininghaus <frank78ac () googlemail ! com>
Date: 2011-08-29 11:33:49
Message-ID: CAFoZWWguvkLFNnY0Vftp6MqPNUnHXfk3q0siBH3r7DV=CGgWDw () mail ! gmail ! com
[Download RAW message or body]
Hi Stefan,
2011/7/29 Stefan Majewsky:
> Hi,
>
> I have a C++ class that implements a Composite pattern. Relevant code follows:
>
> -----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
>
> class Compound : public Entity {
> void addChild(const QByteArray& key, Entity* newChild)
> {
> Q_D(Compound);
> Entity*& child = d->m_children[key];
> delete child;
> child = newChild;
> }
> ~Compound()
> {
> Q_D(Compound);
> typedef QHash<QByteArray, Entity*>::const_iterator Iterator;
> Iterator it1 = d->m_children.constBegin();
> const Iterator it2 = d->m_children.constEnd();
> for (; it1 != it2; ++it1)
> delete it1.value();
> }
> };
>
> -----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
>
> If I run valgrind --leak-check=full against some example code
> instantiating a tree of Compound and Entity instances, it complains
> about a memleak in the second line of Compound::addChild.
could it be that the destructor of EntityPrivate is not virtual?
Cheers,
Frank
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic