11-10-2010 03:25 AM
I could understand using a time delay in a While Loop that DOESN'T contain an Event Structure so as to limit the number of loops it can process per second, but I don't see how this can help when using an Event Structure inside a While Loop since the loop is only executed when an Event is Triggered and in my application that is not very often.
Ah I just read your other e-mail. Don't you mean CPU usage rather than Memory usage. Like I said above this wont help when using an Event Structure inside a While Loop since CPU usage will be 0% when no Events are being processed.
Using the Time delay in a While Loop only affects the CPU usage and not the Memory usage.
Chris
11-10-2010 03:52 AM
Ya thats my mistake. Can you post any other Screen shots that explains the functionlity of the code. Have you checked the CPU usage of your system while running the code?
11-10-2010 04:19 AM
Well its pretty huge so I don't think I can post the code.
It really is just a simple State Machine and it doesn't do anything complicated. It reads and writes to a couple of databases now and again and prints a couple of labels, and it's all controlled by the user through the Main GUI (attached), so the CPU usage is practically zero most of the time.
Even for the worse case event when I Sync all the Folders and Databases the CPU usage only goes up to 50% for a few seconds.
No I think there is something else that is causing the application to not shutdown properly - an open reference to a VI or an ActiveX method or something, but I don't know how I can verify this?
Chris
11-10-2010 04:23 AM
Are you closing the vi reference properly when you stop the VI?...
11-10-2010 05:05 AM
Well I've tried three completely independent methods (JKI's, MGI's and my own) and none of them work, so I don't think all three methods could be wrong, which leads to me suspect that the problem lies elsewhere, but godness knows where
Chris
11-10-2010 09:43 PM
Well I found out where all the memory was being consumed - it occured when I did a couple of SQL queries on the database using the NI connectivity toolkit.
On my development machine (not the exe application), when I ran the main application LabVIEW consumed about 120MB of memory, but when I ran the code below it jumped to about 340MB!! and did NOT release the memory even though I used the Tools Free Object VI after each SQL Query. The only way to recover the memory was to completely Quit LabVIEW.
As you can see below I open a connection to the database and then do four SQL queries in series, and it is the third one that returns a 2D array (23,000x8) of strings that hogs all the memory.
So......
a) How come this one query requires around 200MB of memory to execute when the VI below just converts the Variant data from the database (which is all strings anyway) to a 2D string array which is then written to a standard text file 2MB in size.
b) Why isn't the memory released when I either free the SQL Query or close the connection to the database.
11-11-2010 08:02 PM
Well things just got a little weirder. It seems that if I minimise then restore my main GUI screen the memory usage of the application falls dramatically from 250MB down to 3MB - what the hell
So it seems that after each sync with the database I will have to minimise then restore my main GUI to recover my memory - yuk!!
Can anyone explain what is going on and why do I get this behaviour?
Chris
11-11-2010 11:28 PM - edited 11-11-2010 11:33 PM
Check out this thread. minimize window vs memory usage
Also LV memory leak - How to use windows API SetProcessWorkingSetSize (from Kernel32.dll)
I did a search on "minimize window memory" and there are other messages threads with similar issues.
11-12-2010 01:23 AM
Well that discussion opened a big can of worms didn't it - thanks for that.
OK this pretty much explains most of the issues I've been seeing, EXCEPT the huge increase in memory usage from 70MB to 250MB when I do my SQL Query, but I guess I can leave that for another day.
Thanks once again for that link - Chris