LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

memory leak in while loop

Hi there!

I've set up a program as follows: after some initialization in the sequence structure (indicated near the bottom) it sticks to the last frame running a perpetual while loop. This loop gets executed roughly twice (due to slow device communication) a second. After a few weeks my vi refuses to exit (i.e. it's stuck on the last sequence frame, displaying the hourglass and only the task manager can kill it; trying to exit it in the first one or two weeks works fine) and hogs the computer (up to the point of it no longer finding c:\). I honestly never grasped the business of reentrant vi's (I'd be grateful for links to some documentation), maybe this is causing my problem? Maybe I'm occupying memory in every pass through the loop by creating a new set of references and property nodes?

Any hint is greatly appreciated!

Regards,

Severin

 

P.S.: This is using LabView 8.0.1 on Windows XP

Message Edited by severin on 09-15-2008 03:20 PM
0 Kudos
Message 1 of 8
(4,454 Views)

Judging by the image you posted....

 

 

 

 I would have to first question the "log status every 5 seconds".

 

Ben

 

Message Edited by Support on 09-16-2008 11:14 AM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 8
(4,450 Views)

Hi Ben!

Thanks for your reply. So you think the problem is not the while loop, but within one of the subvi's I keep calling? If so, I don't think the logging is to blame, since all the other subvi's get called roughly twice a second. 

Anyway, to get back on the spot: you don't see anything wrong in my perpetual creating references and property nodes?

 

Best wishes,

Severin

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

severin wrote:

Hi Ben!

Thanks for your reply. So you think the problem is not the while loop, but within one of the subvi's I keep calling? If so, I don't think the logging is to blame, since all the other subvi's get called roughly twice a second. 

Anyway, to get back on the spot: you don't see anything wrong in my perpetual creating references and property nodes?

 

Best wishes,

Severin


 

Boy you are fast to rule out the most likly suspect.

 

Use "Tools >>> Profile >>> Performance and Memory" daily to see if memory usage is climbing for any of your sub-VIs.

 

The control references shown in your screen shot are all static so there should not be a leak in using them.

 

With the screen shot you shared that is all I can do to hlep you for now.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 8
(4,433 Views)

There is no way for us to troubleshoot an image. We need actual code and all subVIs if possible.

 

Many features of your code are very inefficient, but they should not lead to a memory leak, still:

 

  • You seem to be exclusively use value properties to access controls and indicators. Therese are orders of magnitude less efficient than wires (or even local variables) Why not read from the terminal directly?
  • Use a simple tick count to check for deltaT, there is no need to get data/time and convert to U32.
  • You could do a +5 inside the case when you log, instead of with every iteration of the loop.
  • You have many coercions going into the subVIs. Find out why.
  • You should only write properties (e.g. disabled) when they change, not with every iteration of the loop.
  • What is in the other event cases?
  • What does the "logging" do? Append to file?

 

I, too, suspect that the problem is in one of your subVIs, but there is no way to tell for sure without doing some profiling.

Message 5 of 8
(4,416 Views)

Thanks for the hints, I think I've solved my most pressing problem: indeed the Logging procedure did not (*cough* *cough*) close the file after writing to it. Stupid me. So this might lead to Labview releasing lots of open file handles when exiting. We'll see. Now referring to your points:

* I'll try to get rid of the value properties. However this brings up two questions: what is the difference in speed and memory footprint when comparing wires to local variables? What is the most decent way to pass variables to SubVIs. Whenever I have to edit the variable (or access some Property, like grey out a Front Panel element) I use references - are these any good? In OOP usually it's pretty easy to access the caller's variables, is there something similar in Labview?

* I've cleaned up my time counting. Thanks for pointing out

* I understand the concept of coercion dots, however I don't see how this applies to references. I know I shouldn't wire a U8 to a subVI expecting an I32, but what is the size of a reference? How can they be different, how can I fix them?

* on a related note: What number type does "Open/Create/Replace file" expect? I changed my constant to everything from I8 to U64, but got coercion dots no matter what. The help shows some funny representation like "<>"

* If I'm going to only write properties when they change, don't I have to read them every time to be able to figure out *whether* they've changed? Wouldn't this make the whole process just as expensive? Or did you imply it's faster to keep a copy of my property in a separate U8?

 

Regards,

Severin

0 Kudos
Message 6 of 8
(4,370 Views)

severin wrote:
[...]
a) I'll try to get rid of the value properties. However this brings up two questions: what is the difference in speed and memory footprint when comparing wires to local variables? What is the most decent way to pass variables to SubVIs. Whenever I have to edit the variable (or access some Property, like grey out a Front Panel element) I use references - are these any good? In OOP usually it's pretty easy to access the caller's variables, is there something similar in Labview?
[...]

b) I understand the concept of coercion dots, however I don't see how this applies to references. I know I shouldn't wire a U8 to a subVI expecting an I32, but what is the size of a reference? How can they be different, how can I fix them?

c) on a related note: What number type does "Open/Create/Replace file" expect? I changed my constant to everything from I8 to U64, but got coercion dots no matter what. The help shows some funny representation like "<>"

[...]

 

Regards,

Severin


I changed some of the stars of your list to a), b) and c) in order to answer.

 

a) You have to use references if you want to change properties of the fp-element during runtime (e.g. disable). There is no way around that, but you still can waste performance if working bad with this mechanics. There is only one property which should not be adressed using references: the value. The best thing is to use wires (speed and memory), then use variables (speed) then use property nodes (see here). 

 

b) References can be 'typified'. There are three "states" of references: not typified, typified and strict typified. Connecting e.g. a typified reference to a strict typified reference will create a coercion dot. Use "to more specific class" and "to more generic class" to cast references as needed.

 

c) The input is a typified enum. Best thing you can do: rightclick the connector and select: create constant/control.

 

just some hints,

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 7 of 8
(4,362 Views)

Yes, not closing the file references was probably your main problem. All other issues are more cosmetic than anything else and only

really need to be addressed if you have performance or memory problems. Still, I always recommend clean and stremlined code. 🙂

 

There was no way for us to point ot the file problem, because it was not visible in your code. Do you always write to the same file?

In this case you would open the file once before the loop, keep it open during the loop, append data as needed, and close the file once the loop finishes. 


severin wrote:

* on a related note: What number type does "Open/Create/Replace file" expect? I changed my constant to everything from I8 to U64,

but got coercion dots no matter what. The help shows some funny representation like "<>"


The easiest way to get the correct type is always to right-click the terminal and select "create constant|indicator|control" as needed.

You did not say which input you mean, but both the "operation" and "access" inputs are enums. Use enums instead of numerics to

make the code much easier to read. Who wants to constantly query the help pages or memorize the mappings to numbers? 🙂


severin wrote:

* If I'm going to only write properties when they change, don't I have to read them every time to be able to figure out *whether* they've

changed? Wouldn't this make the whole process just as expensive?


No, checking for a change is trivially cheap compared to a property node. In newer LabVIEW versions you would use a globally initialized feedback

node and a simple "not equal" comparison of the current and previous value to see if the value has changed. If I remember right, there is also an openg tool for this.

Message Edited by altenbach on 09-16-2008 09:08 AM
Message 8 of 8
(4,318 Views)