LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how does labview release memory with subVI's


adamsdaq wrote:
This could be an issue infact I know quite a bit of my lower level code has been written this way. As for why I do it that way it is likely more of a factor of me not being a programmer and only learning how to use labview in the past 3months or so. Visually it makes more sense to do it the way I have been doing than trust the auto indexing. Do you think I may need to go back and rewrite all of my code to fix the issue or upon completion of the memory intensive VI am I then releasing that block of memory?

I find auto-indexing tunnels much easier to follow, but maybe that's just years of looking at LabVIEW code.  It's less space on the block diagram and immediately clear that it iterates through each element of the array (or generates one element per iteration of the loop, for an outgoing tunnel).  There's no reason not to trust auto-indexing, it's been a part of LabVIEW for as long as I've used it.

 

You will likely see an improvement in execution speed if you go back and rewrite your code to either pre-allocate arrays or allow LabVIEW to do so by using auto-indexing.  Pre-allocation is necessary in some cases, for example where you want to display the entire contents of the array as it's being built, which you're doing showing the files that have been processed.  You don't need to rewrite your code if it works now, but performance will probably benefit if you do.

 

You're building an array of strings (the files that have been processed).  At first, it allocates a zero-length array.  Then you add an element, so it allocates a new 1-element array, copies the value to that element, and frees the 0-length array.  The next iteration, it needs to add another element, but there's probably something else already allocated just past the 1-element array, so it finds the next open space large enough to hold 2 elements, copies the existing element and the new one, and frees the 1-element array.  The iteration after that, same thing, except now it's copying 2 elements and needs a longer space.  This leaves behind a chain of small blocks of free memory that aren't necessarily contiguous and so can't be combined into a larger block, and all that copying is time consuming.  When you pre-allocate the array, you only need to copy one new element on each iteration - much faster than copying an entire array - and you don't fragment memory. 

0 Kudos
Message 11 of 18
(1,802 Views)

I dont know how LV works under the hood, but i wouldn't be surprised if there's some Java/C# similarities in this regard. What C# do is allocate 50 slots once an array is created and if it needs more, it'll double the length (or if it was Java). It's a clever way to handle the battle between unnecessary memory allocation and time/mess to request new memory. The time difference in newer LV's between preallocated arrays compared to Build arrays is quite small suggestion some similar approach is used.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 12 of 18
(1,784 Views)

What did you mean by not closing properly?  Did you not close it at all?

I am having a very similar problem but it sure appears that I am closing each file correctly.  Oh and the Desktop Excection Trace Toolkit now causes massive leak on my VI while running....Getting ready to pull hair out.

0 Kudos
Message 13 of 18
(1,357 Views)

@BG103 wrote:

....Getting ready to pull hair out.


Instead of adding to ancient threads (some already marked as solved) with little new information, I would suggest that you should start a new thread, show what you are doing, show what you expecting, and show what you expect to happen instead. You can always add links to existing discussion if they are relevant. Thanks.

0 Kudos
Message 14 of 18
(1,334 Views)

Believe me, I have been on many other threads and this one hit the nail on the head closest to the specific question I had.  So since you took the time to tell me to re thread, did you have an answer to my question?

0 Kudos
Message 15 of 18
(1,326 Views)

This thread has many messages, so we have no idea what you are referring to.

 

Your words are way too ambiguous, e.g. "What do you mean" (which post are you talking about?) and "very similar problem" (simular to what exactly?).

0 Kudos
Message 16 of 18
(1,322 Views)

Sorry for the dumb question then, I thought when I hit reply on someone's post, it would reference that specific post, not just add a new post at the end.  That makes since why you don't know what I was asking.  Basically I was looking for more clarification on the "solved solution" that says to make sure to close tdms files "correctly".  Is there a way to close them incorrectly?

0 Kudos
Message 17 of 18
(1,313 Views)

Yes, reply handling is not ideal here in the forum.

0 Kudos
Message 18 of 18
(1,290 Views)