LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

what difference does it make to put a "obtain notifier" inside a while loop and outside a while loop?

I am trying to send notifier when needed from one while loop to another.  What is the difference between initiating the Obtain Notifier outside the MASTER while loop and inside?  Does putting it inside mean a lot of memory will be taken after a number of executions?
0 Kudos
Message 1 of 6
(3,202 Views)
Yes.  Putting it inside the loop means a new notifier is obtained on each iteration of the while loop and it will slowly eat up the resources until the program finally crashes when it runs out of memory.
0 Kudos
Message 2 of 6
(3,201 Views)

To add:

 

You will get the same notifier each iteration if you use a named notifier (and execution time will increase unmeasurable).

But: If you use occurances, you will always get the same occurance.

 

Felix

0 Kudos
Message 3 of 6
(3,192 Views)

Ravens Fan wrote:
... it will slowly eat up the resources until the program finally crashes when it runs out of memory.

Come to think of it, a notifier is just a reference, which is basically an integer value , so I wonder which would happen first - hitting the boundary of an I32 or running out of memory due to references not being closed. I had a similar situation a few years back in which I hit the former due to a coding error (obviously), but I don't remember if I was working with notifiers or queues. Does LV 2009 work any better at "garbage collecting" in closing references that are no longer "referenced"? 

0 Kudos
Message 4 of 6
(3,176 Views)

smercurio_fc wrote:


...which would happen first - hitting the boundary of an I32 or running out of memory due to references not being closed.


Well, 2^31*4 is roughly 8 GB or RAM, so I'm guessing you'll run out of memory on a 32 bit system and possibly reach the limit if you're on a 64 bit system with enough RAM. Also, I'm guessing the reference pool is shared by other resources (like queues), so you probably can't use all of it to allocate notifiers.

 

That said, your experience seems to indicate otherwise (assuming your memory is trustworthy 😉 ).


Does LV 2009 work any better at "garbage collecting" in closing references that are no longer "referenced"? 


I'm guessing the answer is no and that if you allocate a reference which you don't use, it will remain in memory until that hierarchy goes idle. LV does have an optimization where code whose outputs are not used isn't executed at all, but I'm not sure if this applies to obtaining references as well, since that has further implications than just that point in the code.


___________________
Try to take over the world!
0 Kudos
Message 5 of 6
(3,163 Views)

Does LV 2009 work any better at "garbage collecting" in closing references that are no longer "referenced"? 

LV2009 to my knowledge has the exact same method for cleaning up references as previous versions. When a VI goes idle (the top-level VI calling it stops), it cleans up all references it has opened that haven't been closed. It is not a good idea to wait for this to happen automatically.

 

Also, since notifiers can be named, it's difficult to know when they're no longer being referenced. At any time a new reference can be obtained by name.

Jarrod S.
National Instruments
0 Kudos
Message 6 of 6
(3,123 Views)