QCamera, QCameraImage Memory Leak ?



  • 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


  • Lifetime Qt Champion

    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.



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

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


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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.