cureos / csipopt

.NET interface to Ipopt non-linear optimizer
http://code.google.com/p/csipopt/
Eclipse Public License 1.0
19 stars 11 forks source link

Memory Corruption Issue on Multiple Calls #5

Open johneddy101 opened 11 years ago

johneddy101 commented 11 years ago

I am having a memory corruption issue while using CSIPOPT in my code. I've boiled it down into a project that demonstrates the issue. It is a simple optimization problem. The issue occurs when I run it over and over in a loop. If there is some way to transfer the example problem, I'll be more than happy to do that. I linked against the pre-built 1.0.0 binaries. The stack trace is as follows:

at Cureos.Numerics.IpoptAdapter.FreeIpoptProblem(IntPtr ipopt_problem) at Cureos.Numerics.IpoptProblem.Dispose(Boolean disposing) in C:\Users\anders.CUREOS\Documents\Visual Studio 2010\Projects\csipopt\src\IpoptProblem.cs:line 658

Any help would be appreciated.

Thanks! John

Ledragon commented 6 years ago

Hi, I know it's 4 years later, but did you by any chance find a solution to this? I just ran into this same problem yesterday... I realized that disposing the problem does not seem to release all resources: when processing multiple problems in the same process, the log files report increasing CPU time from resolution to resolution, and the heading line is only reported once. I herewith enclosed the log files from running the same problem twice in a unit test. Any hint on how to go from there?

ipopt.unittest2.txt ipopt.unittest0.txt ipopt.unittest1.txt

johneddy101 commented 6 years ago

Hello Hugues,

Yes I did find a solution to this problem. I posted it back then but see that it is not shown in the thread for some reason. Regardless, here it is.

I have a class that inherits IpoptProblem as I’m sure you do as well. Whenever I want to execute a solve, I declare a new instance of my IpoptProblem derivative using Using notation (in VB.NET, using in C#) as below.

' ndv is the number of design variables.

Dim objVal = Double.MinValue

Dim x(ndv - 1) As Double

' Solver inherits IpoptProblem

Using s As New Solver( ....)

s.AddOption("print_level", 0)

s.AddOption(...

...

stat = s.SolveProblem(x, objVal)

End Using

Of course the ellipsis’ above would be replaced by appropriate arguments and statements.

For whatever reason, this results in proper release of resources and no memory corruption or leaking.

Hope this helps,

John

From: Hugues Stefanski [mailto:notifications@github.com] Sent: Wednesday, November 22, 2017 12:48 AM To: cureos/csipopt csipopt@noreply.github.com Cc: johneddy101 johneddy101@gmail.com; Author author@noreply.github.com Subject: Re: [cureos/csipopt] Memory Corruption Issue on Multiple Calls (#5)

Hi, I know it's 4 years later, but did you by any chance find a solution to this? I just ran into this same problem yesterday... I realized that disposing the problem does not seem to release all resources: when processing multiple problems in the same process, the log files report increasing CPU time from resolution to resolution, and the heading line is only reported once. I herewith enclosed the log files from running the same problem twice in a unit test. Any hint on how to go from there?

ipopt.unittest2.txt https://github.com/cureos/csipopt/files/1495000/ipopt.unittest2.txt ipopt.unittest0.txt https://github.com/cureos/csipopt/files/1495001/ipopt.unittest0.txt ipopt.unittest1.txt https://github.com/cureos/csipopt/files/1495002/ipopt.unittest1.txt

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cureos/csipopt/issues/5#issuecomment-346269219 , or mute the thread https://github.com/notifications/unsubscribe-auth/AFTf45OsET3J-bW70tBXAzryTcNJsKaLks5s49GjgaJpZM4BC2mO .

Ledragon commented 6 years ago

Thanks for the reply. Using the using statement does not seem to solve the problem in my case.