I built a safe thread singleton class, which holds memory that is allocated using cudaMalloc().
The instance of the class is saved in the singleton using a C++ auto_ptr smartpointer.
So that whenever I leave the program, the destructor is automatically called.
In the destructor I make sure the memory is release using cudaFree().
When I call exit(0) the program will crash (EXC_BAD_ACCESS) on cudaFree().
If I manually release my singleton just before the call to exit(0), it will not crash.
The point is that manually releasing the singleton is not acceptable.
In this version, the program will crash in the destructor ~T (ClearMemory) on cudaFree when exit(0) is called.
The only explanation I imagine is that some kind of cuda context is erased first, then my auto_ptr is deleting my instance, calling the destructor that calls cudaFree.