LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Open VI reference freezes

Open VI reference seems to run in the user interface thread. If you open a user dialog all the open vi reference functions halt until the dialog has been closed (even though they run in paralell loops etc, no data flow explanation).
Message 1 of 7
(3,684 Views)
You are absolutely correct in this observation.

The UI thread is single threaded.

I write my own dialogs VI and make sure they are not set as "modal" to avoid this situation.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 7
(3,684 Views)
Yes, but why do NI make the open reference run in the UI thread? (there is no way to change that as far as I know), it's the worst thread to have any general function run in...
0 Kudos
Message 3 of 7
(3,684 Views)
> Yes, but why do NI make the open reference run in the UI thread?
> (there is no way to change that as far as I know), it's the worst
> thread to have any general function run in...

The open reference doesn't really have much choice but to be in the UI
thread. It needs to be able to load and possibly even recompile your
VI. It then needs to change its state and build a reference. Perhaps
someday, there will be enough protections and coordination within the
innards of LV to allow many threads in there to do this at once, but
that is some complex code, and it may be awhile.

There is actually a second thing that keeps the reference from
completing, and that is because when a modal dialog is up, it is hard to
tell what is already under
way. For this reason, LV will prevent certain
actions from going in while a modal dialog is up. Now and then, we will
discover a way to loosen this up a bit, and fewer and fewer restrictions
are placed on operation when a modal dialog is up. My suggestion is to
load things up a bit earlier and hold onto the references. You can swap
these out and load others at well known times in your app, not
necessarily in totally parallel oblivion.

Greg McKaskle
0 Kudos
Message 4 of 7
(3,684 Views)
Loading and holding the references at startup is the solution I suggested to the developer who ran into this, for some reason I've never discovered this limitation myself. So it's not a big problem, but one (too) easily overlooked.

We do however more and more develop application where there are parallell independent (should be that is) operations going on all the time, and this seems to introduce problems that are not always what one would expect. The memory leak described in the following is one example:

http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=506500000008000000B7A40000&USEARCHCONTEXT_CATEGORY_0=_49_%24_6_&USEARCHCONTEXT_CATEGORY_S=0&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0
0 Kudos
Message 5 of 7
(3,684 Views)
> Loading and holding the references at startup is the solution I
> suggested to the developer who ran into this, for some reason I've
> never discovered this limitation myself. So it's not a big problem,
> but one (too) easily overlooked.
>

True, this limitation has been there since LV5. It is a temporary
ordering of things that resolves itself as soon as the modal VI goes
away, so it very rarely affects an application.

> We do however more and more develop application where there are
> parallell independent (should be that is) operations going on all the
> time, and this seems to introduce problems that are not always what
> one would expect. The memory leak described in the following is one
> example:
>

This looks a bit like a sneaky way of asking me to look at your "memory
leak" problem. I modified it a bit, changed the delay to 20ms instead
of 50, and made the button be a switch instead of latched, so I could
just let it clone all by itself. Running it in a normal version of LV,
I let it create and then I'd delete. All total, I created and destroyed
about 300 VIs, and the memory on my LV for OSX would go up a few megs,
then back down, then back up bit. I then tried it with a debug version
where I can look at the amount of memory that LV thinks it has allocated
at any point in time.

My quick diagnosis? It isn't a leak, but the extra memory usage is due
to fragmentation. Basically this stems from the fact that loading a VI
means bringing quite a bit of stuff into memory. To do this LV asks the
OS for some allocations. When tearing down the VI, LV frees the
allocations, if it didn't, this would cause a leak.

But, just because allocations are freed doesn't mean the system will
show them as free to give to another app. Here is why. If a program
asks for one byte, the OS will add one page of memory to the app -- that
is 4096 bytes. If the app asks for another byte, the OS doesn't have to
do much, it returns one of the 4095 reserved bytes that belong to the
app. After the 4096 bytes are used, the OS will give the app another
page for 9192 total. Interestingly, if the app starts deleting bytes,
the OS will only be able to take back a page and make it available for
other apps when no allocations are on that page. So leaving the first
byte allocated and say the 5000th byte allocated are enough for those
two bytes of allocation to use up 9192 bytes of memory.

This effect is caused by fragmentation, and it is there largely because
memory is cheap, so the OSes don't do any compaction. 4096 bytes on
even a 64Mb machine is a tiny drop in the bucket, so the OS trades space
for time and wastes memory to increase performance.

So, this isn't a guarantee that this isn't a leak. You did the right
thing in reporting it, and another person in R&D will spend more time to
verify that there isn't a leak, especially in the new AutoClose Refnum
feature. But my quick diagnosis is that as the app loads up a new VI,
some of its lists and arrays grow and are moved to some of the new pages
leaving behind holes. When the VI leaves memory, some of the pages
can't be freed because even though the arrays and lists have shrunk
back, they stay on the new pages. After a few of these chaotic
operations take place, an equilibrium is reached and the app will stop
growing. The pattern it takes, and the amount it grows is highly
dependent on the OS and the heap manager in use. So, on OSX mine may
only grew 3M, whereas one version of windows may grow 4M and another
10M. At any point, it is largely out of LV's control and isn't a true leak.

I hope this helps.
Greg McKaskle
0 Kudos
Message 6 of 7
(3,684 Views)
Got to be sneaky sometimes;-)

The thing is though that whether it's a leak or fragmentation is of less importance. The question is, how can the functionality be implemented in LV without risking a memory problem?

With a stripped down to the bone VI the fragmentation or leak causes maybe 3-4MB of memory loss and requires quite a few calls to do so yes...if the VI in question is more complex the problem is much bigger though. The VI that made me wonder will cause an increase of 25-30MB after a lot less calls (you can see that it frees up a lot of memory when destroyed, but still there's a lot that is not, and there does not seem to be any loose ends to explain it...other than this), that's a tough one to explain for a
customer that is digging into a problem and spots it, and on some machines even though memory is cheap that's still a lot of memory, especially to waste on such a thing.
0 Kudos
Message 7 of 7
(3,684 Views)