Index: c/ref/compilation.rst
===================================================================
--- doc/ref/compilation.rst	(revision 1875f4ec2447bb528be359e5369f6574d604860f)
+++ 	(revision )
@@ -1,63 +1,0 @@
-.. _models-complitation:
-
-******************
-Models Compliation
-******************
-SasView model evaluations can run on your graphics card (GPU) or they can run
-on the processor (CPU).
-
-To run on the GPU, your computer must have OpenCL drivers installed.
-
-... give details on how to identify graphics cards, how to tell if OpenCL
-is already installed and where to get drivers if it is not ...
-
-Note that Intel provides an OpenCL drivers for Intel processors.
-This can sometimes make use of special vector instructions across multiple
-processors, so it is worth installing if the GPU does not support double
-precision.
-You can install this driver alongside the GPU driver for NVIDIA or AMD.
-
-Where the model is evaluated is a little bit complicated.
-If the model has the line *single=False* then it requires double precision.
-If the GPU is single precision only, then it will try running via OpenCL
-on the CPU.  If the OpenCL driver is not available for the CPU then
-it will run as a normal program on the CPU.
-For models with a large number of parameters or with a lot of code,
-the GPU may be too small to run the program effectively.
-In this case, you should try simplifying the model, maybe breaking it
-into several different models so that you don't need if statements in your code.
-If it is still too big, you can set *opencl=False* in the model file and
-the model will only run as a normal program on the CPU.
-This will not usually be necessary.
-
-If you have multiple GPU devices you can tell SasView which device to use.
-By default, SasView looks for one GPU and one CPU device
-from available OpenCL platforms.
-
-It prefers AMD or NVIDIA drivers for GPU, and prefers Intel or
-Apple drivers for CPU.
-Both GPU and CPU are included on the assumption that CPU is always available
-and supports double precision.
-
-The device order is important: GPU is checked before CPU on the assumption that
-it will be faster. By examining ~/sasview.log you can see which device SasView
-chose to run the model.
-If you don't want to use OpenCL, you can set *SAS_OPENCL=None*
-in the environment, and it will only use normal programs.
-If you want to use one of the other devices, you can run the following
-from the python console in SasView::
-
-    import pyopencl as cl
-    cl.create_some_context()
-
-This will provide a menu of different OpenCL drivers available.
-When one is selected, it will say "set PYOPENCL_CTX=..."
-Use that value as the value of *SAS_OPENCL*.
-
-For models run as normal programs, you may need to specify a compiler.
-This is done using the SAS_COMPILER environment variable.
-Set it to *tinycc* for the tinycc compiler, *msvc* for the
-Microsoft Visual C compiler, or *mingw* for the MinGW compiler.
-TinyCC is provided with SasView so that is the default.
-If you want one of the other compilers, be sure to have it available
-on the path so SasView can find it.
Index: doc/ref/gpu_computations.rst
===================================================================
--- doc/ref/gpu_computations.rst	(revision 886fa25dbb18c6bb0e504b4c4231771e0f26d910)
+++ doc/ref/gpu_computations.rst	(revision 886fa25dbb18c6bb0e504b4c4231771e0f26d910)
@@ -0,0 +1,56 @@
+.. _models-complitation:
+
+****************
+GPU Computations
+****************
+SasView model evaluations can run on your graphics card (GPU) or they can run
+on the processor (CPU).
+
+To run on the GPU, your computer must have OpenCL drivers installed.
+For information about OpenCL installation see the
+:ref:`opencl-installation` documentation
+
+Where the model is evaluated is a little bit complicated.
+If the model has the line *single=False* then it requires double precision.
+If the GPU is single precision only, then it will try running via OpenCL
+on the CPU.  If the OpenCL driver is not available for the CPU then
+it will run as a normal program on the CPU.
+For models with a large number of parameters or with a lot of code,
+the GPU may be too small to run the program effectively.
+In this case, you should try simplifying the model, maybe breaking it
+into several different models so that you don't need if statements in your code.
+If it is still too big, you can set *opencl=False* in the model file and
+the model will only run as a normal program on the CPU.
+This will not usually be necessary.
+
+If you have multiple GPU devices you can tell SasView which device to use.
+By default, SasView looks for one GPU and one CPU device
+from available OpenCL platforms.
+
+It prefers AMD or NVIDIA drivers for GPU, and prefers Intel or
+Apple drivers for CPU.
+Both GPU and CPU are included on the assumption that CPU is always available
+and supports double precision.
+
+The device order is important: GPU is checked before CPU on the assumption that
+it will be faster. By examining ~/sasview.log you can see which device SasView
+chose to run the model.
+If you don't want to use OpenCL, you can set *SAS_OPENCL=None*
+in the environment, and it will only use normal programs.
+If you want to use one of the other devices, you can run the following
+from the python console in SasView::
+
+    import pyopencl as cl
+    cl.create_some_context()
+
+This will provide a menu of different OpenCL drivers available.
+When one is selected, it will say "set PYOPENCL_CTX=..."
+Use that value as the value of *SAS_OPENCL*.
+
+For models run as normal programs, you may need to specify a compiler.
+This is done using the SAS_COMPILER environment variable.
+Set it to *tinycc* for the tinycc compiler, *msvc* for the
+Microsoft Visual C compiler, or *mingw* for the MinGW compiler.
+TinyCC is provided with SasView so that is the default.
+If you want one of the other compilers, be sure to have it available
+on the path so SasView can find it.
Index: doc/ref/index.rst
===================================================================
--- doc/ref/index.rst	(revision 4a2e1e58ba8a194f35e463fa90bf7bb202119f9b)
+++ doc/ref/index.rst	(revision 886fa25dbb18c6bb0e504b4c4231771e0f26d910)
@@ -9,5 +9,5 @@
    intro.rst
    refs.rst
-   compilation.rst
+   gpu_computations.rst
    magnetism/magnetism.rst
    sesans/sans_to_sesans.rst
Index: doc/ref/opencl_installation.rst
===================================================================
--- doc/ref/opencl_installation.rst	(revision 886fa25dbb18c6bb0e504b4c4231771e0f26d910)
+++ doc/ref/opencl_installation.rst	(revision 886fa25dbb18c6bb0e504b4c4231771e0f26d910)
@@ -0,0 +1,51 @@
+.. _opencl-installation:
+
+*******************
+OpenCL Installation
+*******************
+
+1. Check if you have OpenCL already installed
+=============================================
+
+Windows
+=========
+    The following instructions are based on
+    http://web.engr.oregonstate.edu/~mjb/cs475/DoIHaveOpenCL.pdf
+
+    * Go to: Start -> Control Panel -> Administrative Tools
+    * Double Click on Computer Managment
+    * Click on Device Manager
+    * Click open Display Adapters
+    * Right-click on available adapter and select Properties
+    * Click on Driver
+    * Go to Driver Details
+    * Scroll down and see if OpenCL is installed (look for OpenCL*.dll files)
+
+Mac OSX
+=========
+    For OSXs higher than 10.6 OpenCL is shipped along with the system.
+
+
+2. Installation
+===============
+
+Windows
+=========
+    Depeneding on the graphic card on your system, drivers
+    can be obtained from different sources:
+
+    * Nvidia: https://developer.nvidia.com/opencl
+    * AMD: http://developer.amd.com/tools-and-sdks/opencl-zone/
+
+Mac OSX
+=========
+    N/A
+
+
+.. note::
+    Note that Intel provides an OpenCL drivers for Intel processors:
+    https://software.intel.com/en-us/articles/opencl-drivers
+    This can sometimes make use of special vector instructions across multiple
+    processors, so it is worth installing if the GPU does not support double
+    precision. You can install this driver alongside the GPU driver for NVIDIA
+    or AMD.
Index: sasmodels/kerneldll.py
===================================================================
--- sasmodels/kerneldll.py	(revision 3764ec19842ceaa33adeddefb56ac0c42a15274e)
+++ sasmodels/kerneldll.py	(revision 886fa25dbb18c6bb0e504b4c4231771e0f26d910)
@@ -73,5 +73,5 @@
 import tempfile
 import ctypes as ct  # type: ignore
-from ctypes import c_void_p, c_int32, c_longdouble, c_double, c_float  # type: ignore
+import _ctypes as _ct
 import logging
 
@@ -111,5 +111,5 @@
     compiler = "unix"
 
-ARCH = "" if ct.sizeof(c_void_p) > 4 else "x86"  # 4 byte pointers on x86
+ARCH = "" if ct.sizeof(ct.c_void_p) > 4 else "x86"  # 4 byte pointers on x86
 if compiler == "unix":
     # Generic unix compile
@@ -241,8 +241,4 @@
     if not os.path.exists(dll):
         need_recompile = True
-    elif getattr(sys, 'frozen', None) is not None:
-        # TODO: don't suppress time stamp
-        # Currently suppressing recompile when running in a frozen environment
-        need_recompile = False
     else:
         dll_time = os.path.getmtime(dll)
@@ -301,5 +297,4 @@
     def _load_dll(self):
         # type: () -> None
-        #print("dll", self.dllpath)
         try:
             self._dll = ct.CDLL(self.dllpath)
@@ -308,10 +303,10 @@
             raise
 
-        float_type = (c_float if self.dtype == generate.F32
-                      else c_double if self.dtype == generate.F64
-                      else c_longdouble)
+        float_type = (ct.c_float if self.dtype == generate.F32
+                      else ct.c_double if self.dtype == generate.F64
+                      else ct.c_longdouble)
 
         # int, int, int, int*, double*, double*, double*, double*, double
-        argtypes = [c_int32]*3 + [c_void_p]*4 + [float_type]
+        argtypes = [ct.c_int32]*3 + [ct.c_void_p]*4 + [float_type]
         names = [generate.kernel_name(self.info, variant)
                  for variant in ("Iq", "Iqxy", "Imagnetic")]
@@ -344,15 +339,11 @@
         Release any resources associated with the model.
         """
+        dll_handle = self._dll._handle
         if os.name == 'nt':
-            #dll = ct.cdll.LoadLibrary(self.dllpath)
-            dll = ct.CDLL(self.dllpath)
-            dll_handle = dll._handle
-            #dll_handle = ct.c_void_p(dll._handle)
-            del dll, self._dll
-            self._dll = None
             ct.windll.kernel32.FreeLibrary(dll_handle)
         else:
-            pass
-
+            _ct.dlclose(dll_handle)
+        del self._dll
+        self._dll = None
 
 class DllKernel(Kernel):
@@ -411,5 +402,5 @@
         #print("returned",self.q_input.q, self.result)
         pd_norm = self.result[self.q_input.nq]
-        scale = values[0]/(pd_norm if pd_norm!=0.0 else 1.0)
+        scale = values[0]/(pd_norm if pd_norm != 0.0 else 1.0)
         background = values[1]
         #print("scale",scale,background)
Index: sasmodels/sasview_model.py
===================================================================
--- sasmodels/sasview_model.py	(revision 9c1a59c7aad38fe9dd5dc541a713efe02e4a6804)
+++ sasmodels/sasview_model.py	(revision 886fa25dbb18c6bb0e504b4c4231771e0f26d910)
@@ -575,4 +575,5 @@
                             magnetic=is_magnetic)
         calculator.release()
+        self._model.release()
         return result
 
