LabLynx KB:closing and disposing of process resources and reducing memory leaks

From LIMSWiki
Jump to navigationJump to search

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.