View Full Version : Memory question - scribble example program

17th October 2006, 01:26
What happens memory-wise when the following code is executed in the
Scribble example program?

void ScribbleArea::resizeImage(QImage *image, const QSize &newSize)
QImage newImage(newSize, QImage::Format_RGB32);
newImage.fill(qRgb(255, 255, 255));
*image = newImage;

a new QImage is created on the stack, but isn't deleted when the function exits
because a reference to it is saved in *image???

If the user resizes 100 times are 100 QImages created? When are they deleted?
Is there some automatic deletion going on when c++ re-assigns the
"image" reference?

Thanks for any help, there must be a hole in my grasp of c++ memory management...

17th October 2006, 03:18
Oops, I think I see why I was confused...
since image is an object and not a reference,

*image = newImage;

copies newImage into image, it's not assigning a reference.