I am using IPOPT ( https://projects.coin-or.org/Ipopt ) nonlinear solver for solving some large scale NLP's. It's used with Octave via mex interface provided along with the package. Quite expectedly, while solving large scale problems, memory usage will be high. Once an IPOPT call is finished, Octave still uses a lot of my system memory untill I exit. If I save all the variables in the workspace in a mat file, after the ipopt call, exit octave, restart it and load the variables back, I do not have Octave using all the memory it was using in the last call. So it seems the mex interface did not clean up the memory before coming out of the call. Is there a way to free up all that heavy memory that was being used by the mex function, without having to restart octave ?