PDA

View Full Version : QVector clear()



Persoontje
20th September 2009, 10:22
Hi,

I have a Vector containing GeometricObject pointers. (3d objects I use in my raytracer program). I was wondering if when I call clear() on the vector, only the items of the vector are destroyed or also the GeometricObjects itself are deleted?

Or do I have to clean the pointers and delete the GeometricObjects to avoid memory leaks manually?

scascio
20th September 2009, 10:45
Of course you have to.
Since clear delete the objects managed by your container, it deletes only the pointer and not the objects pointed.

jpn
20th September 2009, 11:36
The qDeleteAll() function from QtAlgorithms might become handy...

scascio
20th September 2009, 15:38
Or maybe your objects are managed by a parent, like a lot of widgets in Qt class hierachy, that are deleted by the owner.

Persoontje
21st September 2009, 16:27
Nope, they are my own objects (no QObjeccts). But QtAlgorithms looks handy ;-)