When the program is finished, it disconnects and frees the DLL. Below is a snippet of code that does that: