-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[Memory leak] Windows LoadLibrary with dll linked with OpenBlas #1152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Somehow test case is missing in your post. Can you dump heap objects from process with leaks? |
Do you still see a memory leak when you reduce your test case to a simple
(Suggestion stolen from http://forums.codeguru.com/showthread.php?504479-Memory-leak-in-DLLMain ) |
Yes. (https://i.imgur.com/CITUqVh.jpg) |
And directly with openblas.dll to isolate any issues with your shim library? |
Yes. Linkedblas.dll is linked with libopenblas.dll |
I've tried directly using LoadLibrary on libopenblas.dll and the memory leak is still present.
|
Further investigations reveals: |
I have some vague recollection of there being problems with dynamic loading of libraries that then make use of thread-local storage, not sure if this is the issue here though. I assume that VS does not provide details of the loss records, but perhaps this is reproducible on Linux (doing dlopen() of libopenblas) with valgrind. |
Thank you very much for your help. I will try to reproduce on linux also. |
FreeLibrary returns zero on failure, I read it on MSDN... |
The type is BOOL of the return value and I thought it makes sense to write if(ret) |
FreeLibraryAndExitThread looks like able to kill worker threads in openblas dll |
I do not see this on Linux, and cannot test on Windows. Seeing that it appears to happen only when you set up multiple threads it could be a handle leak from mutex locks that are not properly released (not that I would know anything about multithreading on Windows but I found a python issue (10363) that looks vaguely similar; also my earlier attempts to fix apparent threading bugs (PR#1052) were limited to the non-windows parts of the code). Another thing though - just how are you noticing the leak, is this with some tool in VisualStudio, or just watching TaskManager which may not be accurate ? |
Come to think of it, could you try the x86 dll I made available in #1073 ? I'm not entirely sure right now but I think I built that one from the development version of that time, which would include the thread locking fixes. |
@m3rik, did you get around to doing further tests ? |
Hello,
I used openblas in a c++ plugin that is loaded using LoadLibrary in Windows. The problem is that if I load and unload the library for a thousand times, there are at least 100 MB of memory leak.
I built a small project for demo purposes.
LinkedBlas.dll - linked with OpenBlas (prebuilt binaries from sourceforge or nuget package)
TestOpenblas.exe - loads linkedblas.dll and frees the library without using anything from it.
The memory leak is present on both architectures x86 and x64.
Is there a problem that I load a library built with mingw in mcvs?
The text was updated successfully, but these errors were encountered: