PDA

View Full Version : Out of graphic memory - application crash after days



kieselwurz
16th October 2016, 16:08
Hi all,

I've designed a program, which shall run 24/7 for several days in order to read some input sensors and update the drawings on my screen. The program two modes, 'config' and 'active'. In the first mode (no inputs read, no graphical update needed), it can run for some weeks without issue. In the 'active' mode it crashes after appr. two days. In the 'active' mode, the program reads the inputs and calls the paintevents.

I've stripped the code down and attached it as a seperate file. 12180

Some explanation to the program structure:
- I wrote an imagecontroller, which loads all required pictures in a QMap of QPixmaps. From there on, all pictures are referenced by a unique id. (QImageController.*pp). This image controller exits only once in the program.
- The 'viewData' class represents a child of abstract class 'genericViewPage' which is a specialized QWidget to draw on. ViewData provides a background picture, which is used in fullscreen, and a QList of 'elementRect' as dynamic content elements.
- 'elementRects' class has a list of 'elementStates' and chooses the current elementState based on the state of the sensor input.
- 'elementState' class is a representation based on a picture and/or text.

This is how the program should work: (and mainly does)
- When starting the program, the imagecontroller loads all required QPixmaps in a QMap. (function addFile(...) )
- The program changes into the 'active' mode.
- From now on the program reads the sensor inputs and calls the 'repaintRequest(...)' of the viewData.
- In 'paintevent()', viewData paints the background and calls the paintevent of the parent (genericviewpage)
- genericPageview repaints all elements in the list (function drawMe(...)).
- Each element asks the current elementState to get a pixmap to draw (function getImage(...)).
- The elementState gets a QPixmap from the Imagecontroller (function getPixmap(...)) and copies it into the required sized qpixmap. If necessary it writes text into it and returns.

This paint process seems to use more and more graphical memory without releasing any/or all. So I end up with not loading images after some hours and eventually a crashing program.
I've tried several ways to get the issue fixed but didn't get it. So I would appreciate, if someone can have a second look and let me know, what am I doing wrong here???

Thanks a lot. Oh, and please let me know, which information you would need to help with the issue.

Dirk

anda_skoa
16th October 2016, 17:35
The attachment link seems to be invalid.

From the sound of it you are leaking memory, like having unmatched new/delete, or you are keeping memory around that you actually don't need anymore.

Cheers,
_

kieselwurz
17th October 2016, 06:49
yeah, sounds like that to me too. However, I cannot find, where the issue comes from. Do you have any suggestions?

anda_skoa
17th October 2016, 07:24
Check if all new are paired with delete, check if you store things in a map or hash and maybe never remove anything.

You can also disable certain code, e.g.not do anything for updates and see if that does not increase memory.
Then the leak must be in the update handling and so forth.

Ideally of course you'd use a leak checker, not sure if Windows has something like Vagrind for Unix systems.

Maybe the clang address sanitizer if you can build with clang.

Cheers,
_

Ginsengelf
17th October 2016, 14:49
Hi, I often used Visual Leak Detector (http://vld.codeplex.com/) together with Visual Studio.

Ginsengelf

kieselwurz
17th October 2016, 19:49
The attachment link seems to be invalid.

Oh, just saw that the code is not readable. Let me link the file once more: 12182

Thx.

Dirk

anda_skoa
18th October 2016, 07:08
My guess would be QImageController::_images growing endlessly.

Cheers,
_