What is the best way (both in terms of time and of memory) to copy image data (to a Qlabel.pixmap or to another Qimage-object)?

1. i have an object (let's call manipulator), that does some image manipulation. To copy the content of the image back i use this method:

Qt Code:
  1. void manipulator::getPhaseMap(QImage *phasemap)
  2. {
  3. int w = _phasemap->width();
  4. int h = _phasemap->height();
  5. QRgb* pBits = (QRgb *) phasemap->bits();
  6. QRgb* _pBits = (QRgb *) _phasemap->bits();
  7.  
  8. for (int y=0;y<h;y++)
  9. {
  10. for (int x=0;x<w;x++)
  11. {
  12. pBits++;
  13. _pBits++;
  14. }
  15. }
  16. }
To copy to clipboard, switch view to plain text mode 

I would have thought, that by copying the content of the pointers, no extra memory would be used. But actually each time this method is executed, it adds 4mb (the images are 1000x1000 pixels in size) to the application. Since i need to do that like once every second, this is a problem!

(i recently found out, i could simply do

*phasemap = *_phasemap;

but i guess this takes a little bit longer, since it's not only the image data that is being copied..)

2. Inside the manipulator-object i have the following method, that copies data back from another structure into the Qimage:

Qt Code:
  1. void manipulator::buf2im(int w, int h, fftw_complex *f, QImage *im, int imag, float border)
  2. {
  3. float col = 0;
  4. double *bounds = new double[4];
  5. find_maxmin(w,h,f,bounds);
  6.  
  7. QRgb* pBits = (QRgb*) im->bits();
  8. for (int i=0;i<w;i++)
  9. {
  10. for (int j=0;j<h;j++)
  11. {
  12. if (imag == 1) col = 255 * (f[i*w+j][1] - border*bounds[2]) / (border*bounds[3] - border*bounds[2]);
  13. else col = 255 * (f[i*w+j][0] - border*bounds[0]) / (border*bounds[1] - border*bounds[0]);
  14. // *pBits = qRgb(col,col,col);
  15. *pBits = col;
  16. pBits++;
  17. }
  18. }
  19. delete bounds;
  20. }
To copy to clipboard, switch view to plain text mode 

When i use the line *pBits = col; i get 1mb of extra memory used. Using the *pBits = qRgb(col,col,col); i get 4mb! How am i supposed to change the image so that i don't get a memory leak?

3. In a similar problem, i then try to show the Qimage inside a Qlabel. This is what i do:

Qt Code:
  1. ui->phaseview->setPixmap(QPixmap::fromImage(_phaseimage.scaledToHeight(ui->phaseview->height())));
To copy to clipboard, switch view to plain text mode 

This also creates another 4mb of extra memory usage.

Could someone point me to the best way to avoid those leaks?

Thanks in advance. (i'm using Qt 4.6.2 on windows)