Jump to content

Memory Leak on Database Reopen


jpc

Recommended Posts

We are experiencing what we believe is a memory leak in Labview 7.1 when attempting to open and reopen an ODBC connection to a SQL database.

I have seen this topic mentioned in several places...

http://forums.lavag.org/Memory-Leak-t9438.html

http://forums.lavag.org/Memory-usage-issue...lkit-t6570.html

http://forums.ni.com/ni/board/message?boar...essage.id=53391

...but, the problem resolution seems to be to just open and close the connection once. OK, you lose 4K of memory and no big deal.

But in our case, we have a control system reading and writing to a SQL database at regular intervals, and would like to re-establish that connection automatically if it becomes broken (server crash, maintenance, backups, etc.). So the app was designed to loop every few seconds trying to reconnect. We wrote the code, it works well unless the server is down for extended periods of time. Then we noticed the app crashes from depleted memory. We isolated the problem to an open/close connection problem just like in the links above.

So my questions are:

Has this been confirmed to be a Labview problem?

Or is it a ODBC problem with SQL?

Does anyone know if NI has ever addressed this issue?

And, yes, we have a workaround in place. The error is flagged and an operator must manually reconnect when the server is determined to be back online. We cannot risk crashing the control system. We would like to go back to the automatic reconnect, but I still haven't seen this memory leak problem resolved. My colleague who wrote code claims Labview 8.5 still has not fixed this problem.

-John

Link to comment

QUOTE(jpc @ Nov 16 2007, 02:53 PM)

We are experiencing what we believe is a memory leak in Labview 7.1 when attempting to open and reopen an ODBC connection to a SQL database.

<snip>

My colleague who wrote code claims Labview 8.5 still has not fixed this problem.

John:

As far as I know, your colleague is correct: ie, this problem has persisted into v8.5. And so has the recommended work around, viz, only perform the open operation ONCE and then pass the reference around in shift registers...

Link to comment
  • 2 weeks later...

I decided to dig into this problem a little deeper to see if I could find the source of the memory leak.

I discovered that opening and closing the ODBC connection alone does not generate a leak. The leak did not occur until I inserted a table read in between the open close. I thought this was odd, because the error cluster generated on the failed open should pass through the read VI aborting its execution. However within the read VI (DB Tools Select Data.vi) is a subVI called DB Tools Error Helper.vi that is executed regardless of whether an error is passed in or not. The memory leak is occurring in this Error Helper VI when processing an error.

I am attaching the test program VI I used with Windows XP SP2, Labview V7.1, and the Database Connectivity Toolkit, which to my understanding has not changed through several Labview revisions. After setting up an ODBC connection to a SQL test database, I run the program and make sure the table can be read with no errors. To check the memory usage, I run the Task Manager and monitor the Commit Charge value.

To simulate a server crash, I unplug the network connection. The Commit Charge value initially jumps, then stabilizes, as the ODBC breaks and the error is realized and displayed. With the switch set to skip the DB Tools Select Data.VI when an error occurs, there is no growth to the Commit Charge memory value. Toggle the switch to allow the error cluster to pass through the Select Data.VI and the memory grows by 4K per loop iteration.

To confirm the leak in the Error Helper.VI, I commented out its use in the DB Tools Select Data.VI (see the 2nd attachment) and reran the test. No memory growth.

I didn't dig any deeper into the Error Helper.VI to find the error source. It does call the "Call Chain" Labview primitive to get a list of all the VIs for reporting errors, perhaps it's in there. The Error Helper.VI is called by quite a few other VIs in the Toolkit, but not the open and close connection VIs, which explains why my initial test results seemed odd (and probably a lot of other things too).

Since our app is running on embedded PCs, commenting out a display routine will serve as a workaround until a fixed version of the Database Connectivity Toolkit comes out.

I hope this helps those who have been frustrated with this problem.

-John

Link to comment

I decided to dig into this problem a little deeper to see if I could find the source of the memory leak.

I discovered that opening and closing the ODBC connection alone does not generate a leak. The leak did not occur until I inserted a table read in between the open close. I thought this was odd, because the error cluster generated on the failed open should pass through the read VI aborting its execution. However within the read VI (DB Tools Select Data.vi) is a subVI called DB Tools Error Helper.vi that is executed regardless of whether an error is passed in or not. The memory leak is occurring in this Error Helper VI when processing an error.

I am attaching the test program VI I used with Windows XP SP2, Labview V7.1, and the Database Connectivity Toolkit, which to my understanding has not changed through several Labview revisions. After setting up an ODBC connection to a SQL test database, I run the program and make sure the table can be read with no errors. To check the memory usage, I run the Task Manager and monitor the Commit Charge value.

To simulate a server crash, I unplug the network connection. The Commit Charge value initially jumps, then stabilizes, as the ODBC breaks and the error is realized and displayed. With the switch set to skip the DB Tools Select Data.VI when an error occurs, there is no growth to the Commit Charge memory value. Toggle the switch to allow the error cluster to pass through the Select Data.VI and the memory grows by 4K per loop iteration.

To confirm the leak in the Error Helper.VI, I commented out its use in the DB Tools Select Data.VI (see the 2nd attachment) and reran the test. No memory growth.

I didn't dig any deeper into the Error Helper.VI to find the error source. It does call the "Call Chain" Labview primitive to get a list of all the VIs for reporting errors, perhaps it's in there. The Error Helper.VI is called by quite a few other VIs in the Toolkit, but not the open and close connection VIs, which explains why my initial test results seemed odd (and probably a lot of other things too).

Since our app is running on embedded PCs, commenting out a display routine will serve as a workaround until a fixed version of the Database Connectivity Toolkit comes out.

I hope this helps those who have been frustrated with this problem.

-John

Link to comment

QUOTE(jpc @ Nov 27 2007, 07:22 AM)

I decided to dig into this problem a little deeper to see if I could find the source of the memory leak... The memory leak is occurring in this Error Helper VI when processing an error.

:thumbup: Great work John! Have you reported this directly to NI?

Link to comment

QUOTE(jpc @ Nov 27 2007, 07:22 AM)

I decided to dig into this problem a little deeper to see if I could find the source of the memory leak... The memory leak is occurring in this Error Helper VI when processing an error.

:thumbup: Great work John! Have you reported this directly to NI?

Link to comment

QUOTE(jpc @ Nov 26 2007, 05:22 PM)

To confirm the leak in the Error Helper.VI, I commented out its use in the DB Tools Select Data.VI (see the 2nd attachment) and reran the test. No memory growth.

I tried to reproduce the problem you are seeing and couldn't with the VIs you attached. Which SQL database app are you using, what driver and version, and what exact strings do you use to open the connection?

Usually these types of problems are leaks in the ODBC database drivers themselves and therefore nothing that can be addressed or fixed in the database toolkit. Plus, if the problem is in that Error Helper VI, there's nothing in there that is specific to the toolkit...that's just plain LV code and would be reported as a bug in LV, not the toolkit.

Please let me know if there is anything specific I need to do to reproduce this and I'll help report it to the appropriate people at NI. I only have access to SQL Server, though.

Link to comment

QUOTE(jpc @ Nov 26 2007, 05:22 PM)

To confirm the leak in the Error Helper.VI, I commented out its use in the DB Tools Select Data.VI (see the 2nd attachment) and reran the test. No memory growth.

I tried to reproduce the problem you are seeing and couldn't with the VIs you attached. Which SQL database app are you using, what driver and version, and what exact strings do you use to open the connection?

Usually these types of problems are leaks in the ODBC database drivers themselves and therefore nothing that can be addressed or fixed in the database toolkit. Plus, if the problem is in that Error Helper VI, there's nothing in there that is specific to the toolkit...that's just plain LV code and would be reported as a bug in LV, not the toolkit.

Please let me know if there is anything specific I need to do to reproduce this and I'll help report it to the appropriate people at NI. I only have access to SQL Server, though.

Link to comment

QUOTE(xtaldaz @ Nov 26 2007, 05:08 PM)

Which SQL database app are you using, what driver and version, and what exact strings do you use to open the connection?

We are using MS SQL Server 2003, and MS SQL Server ODBC Driver Version 2000.85.1117.0 according to the ODBC Data Source Administrator Drivers tab. When I set up the ODBC connection and run the connectivity test, it lists the driver version as 03.85.1117. The strings are going to be specific to the ODBC connection you make and the database you use, so I made them string controls in the demo VI. The ODBC Data Source Name was created in the System DSN tab of the ODBC Data Source Administrator.

I tried the test on both my WinXP desktop, a constantly updated domain machine, and a minimal WinXP SP2 install running as an embedded workgroup computer, and the results are the same.

Let me know if there's anything else I've forgotten to mention. It would be great to get confirmation from someone else before I report anything to NI.

-John

Link to comment

QUOTE(jpc @ Nov 27 2007, 10:09 AM)

We are using MS SQL Server 2003, and MS SQL Server ODBC Driver Version 2000.85.1117.0 according to the ODBC Data Source Administrator Drivers tab. When I set up the ODBC connection and run the connectivity test, it lists the driver version as 03.85.1117. The strings are going to be specific to the ODBC connection you make and the database you use, so I made them string controls in the demo VI. The ODBC Data Source Name was created in the System DSN tab of the ODBC Data Source Administrator.

Well, John, I have a Good News/Bad News situation to report. The good news is that I have the exact same version and drivers for SQL Server and I had no problems creating a small table and reading from it using your VIs. I used both a UDL connection and a System DSN as you are.

The bad news is that I still can't reproduce what you are seeing. The memory reported by Task Manager for LV doesn't budge regardless of whether the DB VIs return an error or not. Does your memory start disappearing as soon as you disconnect your Ethernet cable or should I let this run for a long time?

So I guess we need to figure out what is different between your and my systems.

I'm using LV 8.2.1 on an XPsp2 machine. My database is located on a networked machine and disconnecting my Ethernet cable creates the same error you are working with.

Other than our LV versions being different, what else can you think of?

Link to comment
QUOTE(jpc @ Nov 16 2007, 11:53 PM)
We are experiencing what we believe is a memory leak in Labview 7.1 when attempting to open and reopen an ODBC connection to a SQL database.I have seen this topic mentioned in several places...http://forums.lavag.org/Memory-Leak-t9438.htmlhttp://forums.lavag.org/Memory-usage-issue...lkit-t6570.htmlhttp://forums.ni.com/ni/board/message?boar...essage.id=53391...but, the problem resolution seems to be to just open and close the connection once. OK, you lose 4K of memory and no big deal.But in our case, we have a control system reading and writing to a SQL database at regular intervals, and would like to re-establish that connection automatically if it becomes broken (server crash, maintenance, backups, etc.). So the app was designed to loop every few seconds trying to reconnect. We wrote the code, it works well unless the server is down for extended periods of time. Then we noticed the app crashes from depleted memory. We isolated the problem to an open/close connection problem just like in the links above.So my questions are:Has this been confirmed to be a Labview problem?Or is it a ODBC problem with SQL?Does anyone know if NI has ever addressed this issue?And, yes, we have a workaround in place. The error is flagged and an operator must manually reconnect when the server is determined to be back online. We cannot risk crashing the control system. We would like to go back to the automatic reconnect, but I still haven't seen this memory leak problem resolved. My colleague who wrote code claims Labview 8.5 still has not fixed this problem.-John
QUOTE(jpc @ Nov 16 2007, 11:53 PM)

...but, the problem resolution seems to be to just open and close the connection once. OK, you lose 4K of memory and no big deal.But in our case, we have a control system reading and writing to a SQL database at regular intervals, and would like to re-establish that connection automatically if it becomes broken (server crash, maintenance, backups, etc.). So the app was designed to loop every few seconds trying to reconnect. We wrote the code, it works well unless the server is down for extended periods of time. Then we noticed the app crashes from depleted memory. We isolated the problem to an open/close connection problem just like in the links above.So my questions are:Has this been confirmed to be a Labview problem?Or is it a ODBC problem with SQL?Does anyone know if NI has ever addressed this issue?And, yes, we have a workaround in place. The error is flagged and an operator must manually reconnect when the server is determined to be back online. We cannot risk crashing the control system. We would like to go back to the automatic reconnect, but I still haven't seen this memory leak problem resolved. My colleague who wrote code claims Labview 8.5 still has not fixed this problem.-John

QUOTE(jpc @ Nov 16 2007, 11:53 PM)

...but, the problem resolution seems to be to just open and close the connection once. OK, you lose 4K of memory and no big deal.But in our case, we have a control system reading and writing to a SQL database at regular intervals, and would like to re-establish that connection automatically if it becomes broken (server crash, maintenance, backups, etc.). So the app was designed to loop every few seconds trying to reconnect. We wrote the code, it works well unless the server is down for extended periods of time. Then we noticed the app crashes from depleted memory. We isolated the problem to an open/close connection problem just like in the links above.So my questions are:Has this been confirmed to be a Labview problem?Or is it a ODBC problem with SQL?Does anyone know if NI has ever addressed this issue?And, yes, we have a workaround in place. The error is flagged and an operator must manually reconnect when the server is determined to be back online. We cannot risk crashing the control system. We would like to go back to the automatic reconnect, but I still haven't seen this memory leak problem resolved. My colleague who wrote code claims Labview 8.5 still has not fixed this problem.-John

Hi JohnI had a memory leak with MySQL using LabVIEW 6.1 and it turned out to be the version of OBDC driver. I had to revert to an earlier version, rather than the latest, to solve the problem; namely MyODBC-3.51.04.exe.Attached is the installation document I produced. Don't know if this will solve your problem, but maybe it will provide additional info to help you.Best Regards.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.