-
Notifications
You must be signed in to change notification settings - Fork 36
Memory leak when using jscip.MessageHandler #53
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
Something somewhere needs to be deleted indeed, but I do not think Try adding this to the anonymous @Override
public synchronized void delete() {
super.delete();
swigTakeOwnership();
} That should clear the reference to the |
So the solution mentioned doesn't seem to work. The delete, finalize or MessageHandler::scip_free methods are just never getting called as can be verified with a debugger. I don't think it's the user's responsibility to call I guess I'll have to dive into the SCIP code now to see under which circumstances SCIP deletes my message handler. |
SCIP is supposed to call I believe that your proposed fix is unsafe because, as I understand it, the garbage collector can then destroy your message handler at any time, and then SCIP will call into a freed object, a classic use-after-free crash. |
I see. In my particular case, it doesn't happen, because I always keep a handle on my message handler, because the API I'm implementing assumes, a user can register multiple message handlers that work independently of each other. But in general, you might have a point. I glanced through the source code of SCIP and JSCIP, and I must say, I'm having some troubles understanding it all. For example, in JSCIP, there are methods defined in SCIPJNIJNI like |
It's not a large leak but could become a nuisance for long running applications that solve many optimization problems.
The leak was discovered by accident, while debugging an entirely different issue. The attached screenshot shows a heap dump of our application created by visualvm.
The number of retained
ScipMessageHandler
instances only goes up while running more optimization problems and never down even after explicitly invoking garbage collection.The generated code for
jscip.MessageHandler
has a close method with an empty body defined. I guess the expected behavior would be that it frees_messagehdlrptr
somehow? Or do I need to call some other JSCIP method to free it?In the meantime, workarounds are:
The text was updated successfully, but these errors were encountered: