Results 1 to 2 of 2

Thread: Memory question - scribble example program

  1. #1
    Join Date
    Sep 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Memory question - scribble example program

    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...

  2. #2
    Join Date
    Sep 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory question - scribble example program

    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.

Similar Threads

  1. simple pointer question
    By mickey in forum General Programming
    Replies: 6
    Last Post: 16th June 2006, 10:19
  2. Basic question on new and delete
    By jcr in forum General Programming
    Replies: 25
    Last Post: 14th February 2006, 16:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.