From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DB query increases memory usage - Keeping the last value of the executed DB query

Hello everyone

 

I am developing an application which reads a parameter name as input and gives its description as output. The application is supposed to connect to a database (PostgreSQL) and search in a "reference table" with two columns: 1- description 2- parameter. By connecting to database and using "DB tools execute query", the parameter is found in the reference table and reads the corresponding description.

 

I have developed the database connection and the query task in a SubVI which can be seen in the attachment.

 

I would like to see the description (output) constantly. However, the only solution that I found was executing query continuously in every cycle which leads to occupation of memory and increase of memory usage. So, I put this memory consuming part of the codes in a case structure which gets triggered by a "change detector" button. The memory usage problem solved, but I see the description (output) for a short time before being disappeared and the corresponding string indicator gets empty.

 

I also tried to use "Shift Register", but since the output eventually is stored in an array, it becomes problematic by changing the array size. 

 

Now I am looking for a solution to be able to keep the result of the query execution available to solve this memory usage problem.

 

I would be grateful if you could help me. 🙂

 

 

Best regards

Iman

 

PS: I am using LabVIEW 2012 SP1.

Download All
0 Kudos
Message 1 of 3
(2,772 Views)

First point - you are not closing all of your references! The execute query gives a query recordset reference which (because of the 'default' value tunnels on the case structure) won't necessarily get closed. Always make sure to close and references you open - otherwise you will have memory leaks.

 

Secondly, try this as an option:

Use a variant on a shift register as an efficient local storage lookup table. When you try to retrieve a 'parameter', see if it exists in the variant lookup table - if it does, return it. If it doesn't, then do the database query to find the description and store it in the lookup table.

 

Something like this should give you a good starting point:

DBVariantLookup.png


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 3
(2,750 Views)

Thank you very much Sam for your help.

 

I tried to implement your idea, but it didnn't work properly. (maybe I implemented it incorrectly!)

 

But I think it wouldn't be the best solution for this problem because there are many parameters which should be compared to the database and the parameters are all in an array with several elements. 

0 Kudos
Message 3 of 3
(2,715 Views)