LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory Leak by drawing pictures

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.

 

 

0 Kudos
Message 1 of 8
(3,593 Views)

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.

 

 

Rolf Kalbermatter
My Blog
Message 2 of 8
(3,560 Views)

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.

 

Draw Picture.png

 

Bob Schor

0 Kudos
Message 3 of 8
(3,544 Views)

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.

0 Kudos
Message 4 of 8
(3,538 Views)

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


___________________
Try to take over the world!
0 Kudos
Message 5 of 8
(3,522 Views)
Another symptom that you might notice is that the picture updates get slower and slower.

Something I have done in the past is to break the image up into logical sections. I generate each section independently and only merge them into a single picture just before display. I found that this approach gave me better control over picture memory. For example, when I drew the outline of a pipe, I knew that the routine always started with a blank picture, so accumulation was not possible.

Likewise, it allowed me to optimize operation by only redrawing the portions of the image that changed. Things like scales only needed to be generated once when the program started because they could never change.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 6 of 8
(3,485 Views)

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.

 

 

 

 

0 Kudos
Message 7 of 8
(3,338 Views)

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.  

0 Kudos
Message 8 of 8
(3,312 Views)