File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed
cuda_bindings/cuda/bindings Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -1905,13 +1905,19 @@ cdef cudaError_t getLocalRuntimeVersion(int* runtimeVersion) except ?cudaErrorCa
19051905 cdef cudaError_t err = cudaSuccess
19061906 err = (<cudaError_t (*)(int*) except ?cudaErrorCallRequiresNewerDriver nogil> __cudaRuntimeGetVersion)(runtimeVersion)
19071907
1908- # Unload
1909- {{if 'Windows' == platform.system()}}
1910- windll.FreeLibrary(handle)
1911- {{else}}
1912- dlfcn.dlclose(handle)
1913- {{endif}}
1908+ # We explicitly do *NOT* cleanup the library handle here, acknowledging
1909+ # that, yes, the handle leaks. The reason is that there's a
1910+ # `functools.cache` on the top-level caller of this function.
1911+ #
1912+ # This means this library would be opened once and then immediately closed,
1913+ # all the while remaining in the cache lurking there for people to call.
1914+ #
1915+ # Since we open the library one time (technically once per unique library name),
1916+ # there's not a ton of leakage, which we deem acceptable for the 1000x speedup
1917+ # achieved by caching (ultimately) `ctypes.CDLL` calls.
1918+ #
1919+ # Long(er)-term we can explore cleaning up the library using higher-level
1920+ # Python mechanisms, like `__del__` or `weakref.finalizer`s.
19141921
1915- # Return
19161922 return err
19171923{{endif}}
You can’t perform that action at this time.
0 commit comments