Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
None
-
6.5.1
-
None
-
Visual Studio 2022, Windows.
Description
When running the following code, the memory used by the app increases over time quickly:
Header file:
#ifndef TESTY_H
#define TEST_H
#include <QMainWindow>
#include <QMediaCaptureSession>
#include <QVideoSink>
#include <QVideoWidget>
#include <QCamera>class Testy : public QMainWindow
{
Q_OBJECT
public:
Testy(QWidget* parent = nullptr);
~Testy();
QCamera* camera;
QMediaCaptureSession* capture;
QVideoSink* sink;
QVideoWidget* video;public {}
slots:
void videoFrame(const QVideoFrame& frame);
};
#endif
Source File
#include "testy.h"
#include <QApplication>
#include <QVideoFrame>
#include <QMediaDevices>
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
Testy w;
w.show();
return a.exec();
}
Testy::Testy(QWidget* parent)
: QMainWindow(parent)
, camera(nullptr)
, capture(new QMediaCaptureSession(this))
, sink(new QVideoSink(this))
, video(new QVideoWidget(this))
{
this->setCentralWidget(video);
capture->setVideoOutput(video);
connect(video->videoSink(), &QVideoSink::videoFrameChanged, this, &Testy::videoFrame); const QList<QCameraDevice> cameras = QMediaDevices::videoInputs(); QCameraDevice camDevice;
for (auto c : cameras)
{
// Set the name of an active webcam here
if (c.description().contains("HD Pro Webcam")) {
camDevice = c;
break;
}
camera = new QCamera(camDevice);
capture->setCamera(camera);
camera->start();
}
Testy::~Testy()
{}
void Testy::videoFrame(const QVideoFrame& frame)
{
// This line appears to create the leak.
QImage img = frame.toImage();
}
Attachments
Issue Links
- duplicates
-
QTBUG-111975 QVideoFrame::toImage has a memory leak at 3840 * 2160 resolution
- Closed