When you open a <codeclass="classname">DbEnv</code> or <codeclass="classname">Db</code> object using
<codeclass="methodname">dbstl::open_env()</code> or <codeclass="methodname">dbstl::open_db()</code>, you
do not need to delete that object. However, if you new'd that object and then opened it
without using the <codeclass="methodname">dbstl::open_env()</code> or
<codeclass="methodname">dbstl::open_db()</code> methods, you are responsible for deleting the
object.
</p>
<p>
Note that you must <codeclass="literal">new</code> the <codeclass="classname">Db</code> or
<codeclass="classname">DbEnv</code> object, which allocates it on the heap. You can not allocate it
on the stack. If you do, the order of destruction is uncontrollable, which makes dbstl
unable to work properly.
</p>
<p>
You can call <codeclass="function">dbstl_exit()</code> before the process exits, to release any
memory allocated by dbstl that has to live during the entire process lifetime. Releasing the
memory explicitly will not make much difference, because the process is about to exit and so
all memory allocated on the heap is going to be returned to the operating system anyway. The
only real difference is that your memory leak checker will not report false memory leaks.
</p>
<p>
<codeclass="function">dbstl_exit()</code> releases any memory allocated by dbstl on the heap. It
also performs other required shutdown operations, such as closing any databases and
environments registered to dbstl and shared across the process.
</p>
<p>
If you are calling the <codeclass="function">dbstl_exit()</code> function, and your
<codeclass="classname">DbEnv</code> or <codeclass="classname">Db</code> objects are new'd by your code,
the <codeclass="function">dbstl_exit()</code> function should be called before deleting the
<codeclass="classname">DbEnv</code> or <codeclass="classname">Db</code> objects, because they need to be
closed before being deleted. Alternatively, you can call the
<codeclass="methodname">dbstl::close_env()</code> or <codeclass="methodname">dbstl::close_db()</code>
functions before deleting the <codeclass="classname">DbEnv</code> or <codeclass="classname">Db</code>
objects in order to explicitly close the databases or environments. If you do this,
can then delete these objects, and then call <codeclass="function">dbstl_exit()</code>.
</p>
<p>
In addition, before exiting a thread that uses dbstl API, you can call the <codeclass="function">dbstl_thread_exit() </code>function to release any Berkeley DB handles if they are not used by other threads.
If you do not call the <codeclass="function">dbstl_thread_exit() </code>function or call this function only in some threads, all open Berkeley DB handles will be closed by the <codeclass="function">dbstl_exit()</code>function.
You must call the <codeclass="function">dbstl_exit() </code>function before the process exits, to avoid memory leak and database update loss, if you do not have transactions and persistent log files.