LabLynx KB:closing and disposing of process resources and reducing memory leaks
![]() |
This is an article specific to the Category:LabLynx knowledge base. Its context outside of LabLynx, Inc may not be apparent, thus why it appears inside the LabLynx KB namespace. |
Problem
Memory usage seems to be high or system performance may be sluggish.
Resolution
These changes involve closing and "disposing" of some process resources, which may help clear up — or at least reduce — a memory leak.
Look for the lines objConn.Close() and ds.Dispose().
objConn.Close(): This closes the database connection. In theory it doesn't really reduce memory usage as the "closed" connection object is really just returned to the connection pool for reuse. However, what may happen is this: more connections are created than necessary. Invoking this may mark the extraneous connections in the pool as available for reuse sooner.
ds.Dispose(): This disposes of the dataset object, which may in fact actually have a memory leak issue. Explicitly calling the Dispose method, according to one blog writer, does not completely solve the leak, but it greatly reduces the associated problems. The bottom line, however, is this: using it is just good practice, regardless.