Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QCamera, QCameraImage Memory Leak ?
Qt 6.11 is out! See what's new in the release blog

QCamera, QCameraImage Memory Leak ?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mranger90M Offline
    mranger90M Offline
    mranger90
    wrote on last edited by
    #1

    Hello,
    I've been playing with a little toy application to use QCamera and QCameraImage to snap images from the
    camera attached to my laptop. I've noticed that even if I do nothing with the images, i.e. just capture on a
    timer, there is a noticeable memory leak with each capture. Environment is Ubuntu 12.04/desktop. Video devices
    are either the camera attached to the laptop or a Microsoft Lifecam on USB. I've tried tracing the source code,
    but it eventually goes down a hole to gstreamer/V4L interface.
    The pertinent code is as follows
    @
    bool StandardCapture::Snap()
    {
    _m_Camera->searchAndLock();

    if(_m_ImageCapture->isReadyForCapture()){
        _m_ImageCapture->capture();
    }
    
    _m_Camera->unlock();
    return true;
    

    }

    void StandardCapture::standardImageCaptured(int id, QImage preview)
    {
    Q_UNUSED(id)

    if(_m_Image) {
        delete _m_Image;
        _m_Image = 0;
    }
    
    // copy the image
    _m_Image = new QImage(preview);
    
    // then pass the signal up
    emit SnapCompleted();
    

    }
    @

    Note that even if I don't connect the StandardImageCaptured, the leak will still happen.
    Other notes are: 1. I am not using an ImagePreview to display the images, I just extract the
    buffer in StandardImageCaptured and use that to display. 2. Even though QCameraImage::isReadyForCapture()
    returns true, I frequently get output in the debug window saying that the device is not ready.

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Just a Qt coding style question: why not take advantage of QImage's implicit sharing ?
      It would avoid making several copies of the same image.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • mranger90M Offline
        mranger90M Offline
        mranger90
        wrote on last edited by
        #3

        Hello,
        Thanks for replying.

        There are 2 reasons why I don't use the sharing. 1. This is just a toy app for me to learn a little bit
        about how the interface works and how to manipulate Qimages. I've use the imageviewer and connected everything up and it works nicely, except I didn't really learn anything.
        2. I also use this app to connect to a frame grabber board and use its native API to acquire images, hence the capture code displayed is in a "StandardCapture" class as opposed to the (not shown) "MfgCapture" class. So until I figure out how to connect then frame grabber to the image viewer (without using its V4L interface) I wanted to keep the access consistent.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          I have noticed that the imageCapture->capture(); in the QT camera.pro example also exhibits a memory leak (at least under Linux). I have filed a bug report here:

          https://bugreports.qt-project.org/browse/QTBUG-41606

          I'm actually working on FabScan100 scanner software, and the memory leak blows the PC away after a couple of hundred frames.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved