-
Notifications
You must be signed in to change notification settings - Fork 167
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
Memory leak when used in C++ #155
Comments
Hi @SigmaOrionis, thank you for reporting this! I will however need some more details in order to be able to try to reproduce this. |
Hi, multiple thread call to:
detected in release build attached to console application statically, or as attached dll accessed through CLR. Pozz ;) |
I never used edlib in multiple thread call situation, but I would expect it to behave nicely / not differently than when normally called. One thing to keep in mind: you should call freeEdlibAlignResult() on result of edlibAlign when you don't need it any more. Although I think in your specific case that might not be the problem (because you are using default align config), but you should still do it to be safe. Also, how did you detect that memory leak is happening, and that it is coming from edlib, could you provide more details on that? How much is memory allocation growing, where is it coming from, anything? |
Bok Martin, call to edlibAlign is scoped and as such by all coding standards should free itself. It does not matter that I am calling it from multiple threads, it would leak from single thread. Leak is detected by monitoring memory allocation in my case by using Visual Studio 2019 memory allocation monitor. You know what, here you go:
Incomplete output: . Object dump complete. Pozdrav! |
Thanks @SigmaOrionis! "By all coding standards" -> I believe you are looking at this from the C++ perspective? I have to admit that I am no C/C++ expert, but I don't think that Edlib is going against any coding standards with the current API, which is really a C API, which enables it to be used both in C and C++. It is clearly stated in docs that the resulting object should be freed with the appropriate function. Regarding the memory leak, thank you for this great code example, this helps a lot! #include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#include "edlib.h"
std::string getRandomString( )
{
int randlen = rand( ) % 10 + 1; // rand between 1 and 10
char randChar;
std::string out;
for( int i = 0; i < randlen; i++ )
{
randChar = rand( ) % 122 + 48;
out.push_back( randChar );
}
return out;
}
int main()
{
srand( time( nullptr ) );
std::string one;
std::string two;
for( int i = 0; i < 1000; i++ )
{
one = getRandomString( );
two = getRandomString( );
auto ed = edlibAlign( one.c_str( ), one.length( ), two.c_str( ), two.length( ), edlibDefaultAlignConfig( ) ).editDistance;
}
}
And then compiled and tested it with
to check for leaks and I get
I unfortunately don't right now have time to set up Windows environment to reproduce exactly what you did. |
Sorry Martin, tried to help here, have some other projects to work on. Kind regards. |
@SigmaOrionis np, thanks for help so far. I will leave the issue open, in case somebody with Windows and some time on their hands would like to try to reproduce and possibly fix the possible bug! |
Describe the bug
Memory leak
To Reproduce
Multiple edit distance check.
Expected behavior
Keep memory at the same level
Environment (please complete the following information):
Additional context
Using edit distance as described
The text was updated successfully, but these errors were encountered: