Results 1 to 5 of 5

Thread: xorg memory leak from QPainter::drawPixmap

  1. #1
    Join Date
    Mar 2011
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default xorg memory leak from QPainter::drawPixmap

    Hi all,

    I'm writing an application which dynamically changes the picture on running video streams. The OS is debian based with X11.

    The problem is a slow but surely increasing memory leak reported by process "xorg" (not by my application). A little bit googling hinted that the pixmap paiting on the video could be an issue. I tried to comment the relavant part of the code and the memroy leak disappeared. And then, I started uncommenting bit by bit. Now the whole memory leak has come down to 3 lines of code:

    Qt Code:
    1. // Setting source and target for drawPixmap()
    2. QRectF source(0, 0, currPixmap->width(), currPixmap->height());
    3. QRectF target(0, 0, objectCameraSelectionWindow->getDirectionImageWidth(),
    4. objectCameraSelectionWindow->getDirectionImageHeight());
    5.  
    6. // drawPixmap() is faster on-screen while drawImage() may be faster on
    7. // QPainter or other devices.
    8. painter.drawPixmap(target, *currPixmap, source);
    To copy to clipboard, switch view to plain text mode 

    So, again if I uncomment this code, linux command "top" reports a disticnt memory leak, otherwise not. The code snippet is used inside the paintEvent method:

    Qt Code:
    1. void RenderDirection::paintEvent(QPaintEvent *)
    2. {
    3. QPainter painter(this);
    4. QPixmap* currPixmap=0;
    5.  
    6. // Choose the coirrect bitmap
    7. if(direction == "left"){
    8.  
    9. currPixmap = objectCameraSelectionWindow->getImageOnLeftVideo();
    10. }
    11. else if(direction == "right"){
    12.  
    13. currPixmap = objectCameraSelectionWindow->getImageOnRightVideo();
    14. }
    15.  
    16.  
    17. // Setting source and target for drawPixmap()
    18. QRectF source(0, 0, currPixmap->width(), currPixmap->height());
    19. QRectF target(0, 0, objectCameraSelectionWindow->getDirectionImageWidth(),
    20. objectCameraSelectionWindow->getDirectionImageHeight());
    21.  
    22. // drawPixmap() is faster on-screen while drawImage() may be faster on
    23. // QPainter or other devices.
    24. painter.drawPixmap(target, *currPixmap, source);
    25. }
    To copy to clipboard, switch view to plain text mode 

    As usual, any help is much appreciated.
    Anirban

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: xorg memory leak from QPainter::drawPixmap

    Hi Anirban,

    This is just a hunch, I don't have any knowledge of the X11 video system. But could it be, that the pixmap is cached on the "server"-side? The OpenGL-drawPixmap for instance, binds a glTexture so that redrawing the same pixmap is really fast. How do you release your Pixmaps? Can't you write your new content directly to the same QPixmap instead of creating new ones for every frame?

    Joh

  3. #3
    Join Date
    Mar 2011
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: xorg memory leak from QPainter::drawPixmap

    Quote Originally Posted by JohannesMunk View Post
    Hi Anirban,

    How do you release your Pixmaps? Can't you write your new content directly to the same QPixmap instead of creating new ones for every frame?
    Hi Johannes,

    I don't release any pixmap. As you can see I'm not creating any "new" pixmap. So I guess I don't have to release one.

    For the 2nd question, I don't know how to do that. Please note that I need to scale the pixmap from currPixmap->width() and currPixmap->height() to objectCameraSelectionWindow->getDirectionImageWidth() and objectCameraSelectionWindow->getDirectionImageHeight())

    Please let me know if you have any alternate code to draw the same pixmap in the exact location w/o creating using drawPixmap()

    Thanks,
    Anirban

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: xorg memory leak from QPainter::drawPixmap

    I assumed that objectCameraSelectionWindow->getImageOnLeftVideo(); would return a new QPixmap every frame of the video?

    You could look into qpaintengine_x11.cpp -> QX11PaintEngine::drawPixmap and see how it's done.

    Try to create a minimalistic application that just draws the same pixmap over and over again. Then alternating two. Then your objectCameraSelectionWindow. See what happens.

    Johannes

  5. #5
    Join Date
    Mar 2011
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: xorg memory leak from QPainter::drawPixmap

    Well, the assumption is half-true. It replies with image loaded from file system to be placed on the video.

    Yes the minimalistic approach is a good idea. Will definitely try that. But my hunch tells me this memory leak has something to do with the fact that I'm putting the pixmap over a video.

    Also, the memory leak has no visible effect on the system. I mean if some process is engaging more than 40% of the memory I'll expect significant sluggish behaviour for the application (especially considering the limitation of processor and memory and the fact that I'm running 8 live streams on top of that ).

Similar Threads

  1. Replies: 1
    Last Post: 9th March 2011, 22:50
  2. Memory Leak with QPrinter/QPainter
    By cevou in forum Qt Programming
    Replies: 11
    Last Post: 1st June 2010, 06:24
  3. QPainter::drawPixmap with floats ?
    By christophe.daudin in forum Qt Programming
    Replies: 8
    Last Post: 20th October 2009, 10:19
  4. QPainter::drawPixmap always produces black on windows?
    By spbots in forum Qt Programming
    Replies: 0
    Last Post: 18th September 2009, 16:42
  5. a runtime errors in QPainter::DrawPixmap(..)
    By richardander in forum Qt Programming
    Replies: 1
    Last Post: 12th February 2009, 17:46

Tags for this Thread

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.