Qt seems to leak memory everywhere - windows

I have big problems with memory leaks in Qt.
The problems is that when i run methods like:
qwidget->show();
qwidget->hide();
qwidget->setVisible(...);
qlabel->setText(...);
qwidget->setEnabled(...);
then it leaks memory.
I do not create any objects on the fly. I have created all widgets on startup and I just hiding and showing widgets and changing text on some labels all the time.
And when I remove those methods, then it doesn't leaks memory at all.
Is there someone who know why it is that way or if someone knows what happens under the hood? Or does Qt have memory problems?
I run windows 7 x64 with Qt 5.0.1 x64 in release mode.
Now i have added a test code:
#include "qtmemoryleaktest.h"
#include "Content_Logs.h"
QWidget* m_placeholder;
bool m_toggle;
QtMemoryLeakTest::QtMemoryLeakTest(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
m_placeholder = new Content_Logs(this);
this->layout()->addWidget( m_placeholder );
connect( ui.pushButton, &QPushButton::clicked, this, &QtMemoryLeakTest::toggleClick );
}
void QtMemoryLeakTest::toggleClick()
{
if( m_toggle = !m_toggle )
{
m_placeholder->show();
}
else
{
m_placeholder->hide();
}
}
Memory grows everytime a click on the button. from 8 mb to 47 mb in 20 minutes. But if a replace Content_Logs to a QWidget, no memory leaks. So i Think there is a bug in Qts self gererated ui-classes? In Content_Logs i have labels, lineEdits, Spacers, TableWidgets, Checkboxes, DateTimeEdits, ComboBoxes and so on.
Code in Conte_Logs:
#include "Content_Logs.h"
Content_Logs::Content_Logs( QWidget* parent = 0 )
: QWidget( parent )
{
ui.setupUi( this );
}
Content_Logs::~Content_Logs()
{
}

Related

Graphics debugging in MSVC 2017 - An error occured. Playback of your application may be incomplete

I successfully recorded a DX11 diag session once. When running it the second and any further time, when I click on a frame I get this error:
An error occured. Playback of your application may be incomplete. (HRESULT = 0x00630000) "Unknown error (0x00630000)"
I capture frames programmatically, using the code shown here in Microsoft Docs. It worked before with other shaders as well as the one I'm debugging now.
I have a RAII class for the debugging:
class GPUBlock
{
public:
GPUBlock() : _startResult(DXGIGetDebugInterface1(0, __uuidof(_directXAnalysis), reinterpret_cast<void**>(&_directXAnalysis)))
{
if (debugInitialized())
_directXAnalysis->BeginCapture();
}
~GPUBlock()
{
if (debugInitialized())
_directXAnalysis->EndCapture();
}
bool debugInitialized() const { return _directXAnalysis && !FAILED(_startResult); }
private:
IDXGraphicsAnalysis* _directXAnalysis = nullptr;
HRESULT _startResult = OLE_E_BLANK;
};
Used as:
{
Debug::GPUBlock debugGPUplease;
DoGPUWork();
}
Turns out you must click the "Stop collection" button. If you end the debugging this way, the logs will work just fine.
It is not clear why it worked without it before, but it was probably luck and not normal behaviour.
Also, this error will happen if BeginCapture() and EndCapture() are called at inappropriate moments. You can't just place them wherever! You need to capture the entirety of the GPU operation, including the setup.

WxWidgets and modern opengl (3.3+)

Does anyone know if the WxWidgets library plays well with modern shader style openGL (3.3+)? All the stuff I found seems to be using the old style. I'm looking to use either QT or WxWidgets for my application, but it seems like getting shader stuff to work with widgets might be a nightmare. Does anyone have experience with this?
In wxWidgets >= 3.1 using wxGLContext with an appropriate Core-context wxGLContextAttrs ought to work:
wxGLContextAttrs cxtAttrs;
cxtAttrs.CoreProfile().OGLVersion(3, 3).EndList();
As Ripi2 pointed out from the pyramid sample:
//We create a wxGLContext in this constructor.
//We do OGL initialization at OnSize().
MyGLCanvas::MyGLCanvas(MyFrame* parent, const wxGLAttributes& canvasAttrs)
: wxGLCanvas(parent, canvasAttrs)
{
m_parent = parent;
m_oglManager = NULL;
m_winHeight = 0; // We have not been sized yet
// Explicitly create a new rendering context instance for this canvas.
wxGLContextAttrs ctxAttrs;
#ifndef __WXMAC__
// An impossible context, just to test IsOk()
ctxAttrs.PlatformDefaults().OGLVersion(99, 2).EndList();
m_oglContext = new wxGLContext(this, NULL, &ctxAttrs);
if ( !m_oglContext->IsOK() )
{
#if wxUSE_LOGWINDOW
wxLogMessage("Trying to set OpenGL 99.2 failed, as expected.");
#endif // wxUSE_LOGWINDOW
delete m_oglContext;
ctxAttrs.Reset();
#endif //__WXMAC__
ctxAttrs.PlatformDefaults().CoreProfile().OGLVersion(3, 2).EndList();
m_oglContext = new wxGLContext(this, NULL, &ctxAttrs);
#ifndef __WXMAC__
}
#endif //__WXMAC__
if ( !m_oglContext->IsOK() )
{
wxMessageBox("This sample needs an OpenGL 3.2 capable driver.\nThe app will end now.",
"OpenGL version error", wxOK | wxICON_INFORMATION, this);
delete m_oglContext;
m_oglContext = NULL;
}
else
{
#if wxUSE_LOGWINDOW
wxLogMessage("OpenGL Core Profile 3.2 successfully set.");
#endif // wxUSE_LOGWINDOW
}
}

MFC disk partitioning

I want to get the hard disk partitions,their individual storage capacity and used space. Then display it in some control(List control would be better). I am using MFC to do this. I have searched online and managed to pull of the partitions. But I managed to display it in an edit box only.
void CDiskManagementClientDlg::OnBnClickedOk()
{
wchar_t drive[512]=L"A:";
unsigned int drives=GetLogicalDrives();
CString strListOfDrives=_T("The drives are:");
if(drives==0)
{
AfxMessageBox(_T("No Partitions"));
}
else
{
while(drives)
{
if(drives & 1)
{
strListOfDrives+=drive;
strListOfDrives+=_T(", ");
}
drive[0]++;
drives>>=1;
}
m_newDrives=strListOfDrives;
UpdateData(FALSE);
}
}
This is the code I have used to display the partions in an edit box when a button is clicked. I want to display the partitions in a control. Can someone pls guide me?

How to correctly dispose QLPreviewController?

I'm using QLPreviewController to preview files.
But when I open big files memory grows and don't disposing.
Ex: iPhone 4s, open 6 Mb txt and 5Mb txt after - app will freeze or crash. Look into Instruments - used memory 230Mb.
I have field in class:
private QLPreviewController previewController;
public void OpenAnotherFile()
{
if (previewController != null) {
previewController.DataSource.Dispose ();
previewController.DismissViewController (false, null);
} else {
previewController = new QLPreviewController ();
}
// loading new file here
previewController.DataSource = new QLPreview ();
previewController.ReloadData ();
view.AddSubview (previewController.View);
}
This variant without recreation of previewController, but i tried previewController.Dispose() and recreation. Tried call GC.Collect() - nothing.
I tried many cases (disposing datasource, view and so), but memory is not clearing.
I suggest - I'm not right myself. But where?.
Please, help.
Thanks.

Custom memory allocator for OpenCV

Is it possible to set a custom allocator for OpenCV 2.3.1? I have a memory pool created and I want OpenCV to use that pool for what it needs.
Is that possible?
If it is, how can it be done?
Updated:
I made some developments since last answer, but I still have some problems.
This is the code I have now:
CvAllocFunc allocCV()
{
return (CvAllocFunc) MEMPOOL->POOLalloc(sz);
}
CvFreeFunc deallocCV()
{
return (CvFreeFunc) MEMPOOL->POOLfree(ptr);
}
...
cvSetMemoryManager(allocCV(),deallocCV(),data);
Now, my question is, how can I have access to the size and the pointer to the data I want to allocate and later to deallocate?
Just found out:
The version of OpenCV I'm using (2.3.1) throws an error when using cvSetMemoryManager. The reason is in its source code:
void cvSetMemoryManager( CvAllocFunc, CvFreeFunc, void * )
{
CV_Error( -1, "Custom memory allocator is not supported" );
}
I was very disappointed with this. I guess I can't use a custom memory pool with OpenCV anymore!
Right from the docs
http://opencv.willowgarage.com/documentation/c/core_utility_and_system_functions_and_macros.html#setmemorymanager
Use the
void cvSetMemoryManager(CvAllocFunc allocFunc=NULL, CvFreeFunc freeFunc=NULL, void* userdata=NULL)
function.
Your code
cvSetMemoryManager(allocCV(),deallocCV(),data);
is WRONG.
See what happens: you call allocCV and deallocCV functions (they return some pointer which is quietly converted to cvAllocFunc) !
And this is only the beginning. See the docs for alloc/dealloc semantics. You should write allocCV/deallocCV with correct signatures.
void* CV_CDECL allocCV(size_t size, void* userdata)
{
return ((YourMemPoolTypeWhichIDoNotKnow*)userdata)->POOLalloc(size);
}
int CV_CDECL deallocCV(void* pptr, void* userdata)
{
return ((YourMemPoolTypeWhichIDoNotKnow*)userdata)->POOLfree(pptr);
}
and then pass your MEMPOOL in the 'userdata' parameter:
cvSetMemoryManager(&allocCV, &deallocCV, (void*)MEMPOOL);
This is a standard way for a library to provide user callbacks.

Resources