The following places a bunch of shared_ptr
s containing an arbitrary object in a QList. With the curly braces I create a stack, which triggers the deletion of the list when the instruction pointer leaves it. Somehow the
shared_ptr
s get not deleted. Why? I track the memory consumption in gnome-systemmonitor and htop.
{
QList<std::shared_ptr<QChar>> l;
for (int i =0; i< 1024*1024*10; ++i)
l.append(std::make_shared<QChar>('h'));
}
qDebug() <<"done";
sleep(10);
I just tested it. The same problem with QSharedPointer, but not with regular types (non [shared] pointers).