Warm_start issues

When we use osqp to solve a series topic, the manual said that it will automatically warm start. But do we need to cleanup the work every time after we solve a problem? It seems that there will be a memory leak if we don’t do it.

As long as you are solving the same problem, even if you update the problem data through the OSQP api functions, then you don’t need to call cleanup between solves. OSQP only allocates memory during the osqp_setup phase, so there will be no memory leak if you solve multiple times. It is only necessary to call the cleanup function once after the final solve.

How about the data? I suppose when we need warm_start, we will do the following two lines only once and do cleanup/c_free at the end of the work. Is it correct?

OSQPData* data = reinterpret_cast<OSQPData*>(c_malloc(sizeof(OSQPData)));
OSQPSettings* settings = reinterpret_cast<OSQPSettings*>(c_malloc(sizeof(OSQPSettings)));

Yes, you only allocated the data and the settings one time. If you want to warm start, you should then use the osqp-provided API functions to do so. There is no need to provide the data set or settings again provided you are using the same solver object.