LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Release Semaphore or Release Semaphore Reference

I have a problem with a memory leak in a VI that is using the semaphore VI's.  I found that the VI was using "Release Semaphore" instead of "Release Semaphore Reference".  After reading the help documentation that seems correct, but the memory usage increases when I use "Release Semaphore" instead of "Release Semaphore Reference".  My question is, should "Acquire Semaphore" be paired with "Release Semaphore" or "Release Semaphore Reference", or both?

 

 

0 Kudos
Message 1 of 2
(2,779 Views)

Your problem is that you obtain the reference in the loop. The reference points to a specific semaphore and you only need to obtain it once. If you call it again, you will get a new reference which points to the same semaphore (you can see you get a new one if you place a probe on the reference wire). Each reference is 4 bytes and because you keep getting new ones and doing nothing with the old, your memory usage keeps growing. The reason the obtain VI works like this is to allow you to obtain multiple references to the same semaphore in different places in the code. The same concept is true for queues and notifiers (and rendevouz, I believe, although I don't use those).

 

The solution is to move the obtain VI outside the loop. The rest can stay as it is. Relasing the reference should be done at the end.

 

Also, note that the release reference VI has a force destroy input. This will destroy the actual semaphore even if there are still other references open to it (causing anyone trying to use that semaphore to return errors) and can be useful in some cases.


___________________
Try to take over the world!
Message 2 of 2
(2,753 Views)