12-22-2015 05:57 AM
Hello,
I am experiencing out of memory after a couple of hours when I start my program. In my program I am drawing a picture part onto a big picture. If I deactivate that vi, memory usage doesn't increase. If I activate it memory usage increases app. ~1MB/s. I am drawing 3 small different pictures on it each second. How can I avoid it? I am posting my code.
Thanks.
12-22-2015 08:06 AM - edited 12-22-2015 08:09 AM
That's completely logical. You created a never ending growing memory buffer. The LabVIEW picture control is a control that gets driven by a stream of drawing commands. Each drawing command instructs the picture control to draw a line, circle, box or even a bitmap on the control. The commands can be daisy chained to create complex graphics.
Every loop cycle you take the stream of drawing commands APPEND a new drawing command to plot the bitmap on the control and write that new and longer byte stream back to the control. Can you see the never ending increasing memory buffer that is needed for this?
Basically the Read Value property is completely useless, as you do clear the picture control anyhow, and even if you didn't, plotting a bitmap over another bitmap will always cover the previous bitmap completely, so no use in remembering it.
And as a nitpick, this is not a memory leak. The memory is fully maintained and will eventually get deallocated properly by LabVIEW when you quit the program. What you did is basically similar to a shift register with a string where you append in a loop endlessly new data to the string. The memory keeps growing and eventually consumes all of the memory available but it is not leaked at all.
12-22-2015 08:33 AM
You would hope that LabVIEW would do appropriate Garbage Collection to reclaim the memory release by the Erase First setting. Picture Controls have Erased First set by default -- is it possible you don't need to use this property? I'm also wondering about referencing and dereferencing the Picture In reference ...
I simplified your routine, then pointed it at a file of 300 or so PNGs and said "Draw each of these at 20 pictures/second". It was happy to comply, no errors. Note that I wire the output 2D Picture directly to the 2D Picture (indicator) of the Caller, without passing any references.
Bob Schor
12-22-2015 08:37 AM
What he said. To fix this all you need to do is delete the wire going to the Draw Unflattened Pixmap. This will then append the PNG image on top of a blank image, and memory will not continue to increase.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
12-22-2015 09:12 AM
@Bob_Schor wrote:
You would hope that LabVIEW would do appropriate Garbage Collection to reclaim the memory release by the Erase First setting.
It's unlikely it's relevant. The help for the property says it acts when you update the picture, but as Rolf pointed out, since the current value is read from the picture and fed into the drawing VI, clearing the picture before writing doesn't prevent the accumulation.
12-22-2015 08:53 PM
01-04-2016 03:04 AM
Hi again,
I was on a long holiday, could not go online. Thanks for useful comments and answers.
I think I didn't explain my purpose very clearly. I want to change some part of picture, the whole picture (or backgroung image) shall not be updated with new picture, only a small partition of big picture shall be updated. To be more clearly I upload a picture:
In picture, I will be able to change only s1_off.png with s1_on.png, s2_off.png with s2_on.ong and sys_normal.png with sys_error.png or sys_warning.png.
01-04-2016 08:26 AM
No worries. So there are two ways I can see doing this, and both have been expored in this thread.
https://forums.ni.com/t5/LabVIEW/2D-Picture-Control-Memory-Growth/td-p/2882124
Basically what you could do is after combining all these images, you can flatten it again, so instead of being made up of 5 or so components, it is a single flat image that you can then draw on top of. Or you can keep all of these image components separate, and combine them as needed.
The trick is to not combine iamges that have already been combined, that just leads to more memory being needed to draw the image.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord