@@ -63,13 +63,15 @@ HighsStatus Highs::clear() {
6363HighsStatus Highs::clearModel () {
6464 model_.clear ();
6565 multi_linear_objective_.clear ();
66+ saved_objective_and_solution_.clear ();
6667 return clearSolver ();
6768}
6869
6970HighsStatus Highs::clearSolver () {
7071 HighsStatus return_status = HighsStatus::kOk ;
7172 clearDerivedModelProperties ();
7273 invalidateSolverData ();
74+ ekk_instance_.clear ();
7375 return returnFromHighs (return_status);
7476}
7577
@@ -80,6 +82,61 @@ HighsStatus Highs::clearSolverDualData() {
8082 return returnFromHighs (return_status);
8183}
8284
85+ HighsStatus Highs::releaseMemory () {
86+ HighsStatus return_status = HighsStatus::kOk ;
87+ // 1. Clear all model and solver state (same as clear()).
88+ clearModel ();
89+
90+ // 2. Clear and shrink vectors that clearModel/clearSolver only
91+ // invalidate or leave with residual capacity. After this block the
92+ // instance holds zero allocated heap memory for solver state —
93+ // equivalent to a freshly constructed Highs.
94+ saved_objective_and_solution_.shrink_to_fit ();
95+ solution_.clear ();
96+ solution_.col_value .shrink_to_fit ();
97+ solution_.col_dual .shrink_to_fit ();
98+ solution_.row_value .shrink_to_fit ();
99+ solution_.row_dual .shrink_to_fit ();
100+ basis_.clear ();
101+ basis_.col_status .shrink_to_fit ();
102+ basis_.row_status .shrink_to_fit ();
103+ ranging_.clear ();
104+ ranging_.col_cost_up .value_ .shrink_to_fit ();
105+ ranging_.col_cost_up .objective_ .shrink_to_fit ();
106+ ranging_.col_cost_up .in_var_ .shrink_to_fit ();
107+ ranging_.col_cost_up .ou_var_ .shrink_to_fit ();
108+ ranging_.col_cost_dn .value_ .shrink_to_fit ();
109+ ranging_.col_cost_dn .objective_ .shrink_to_fit ();
110+ ranging_.col_cost_dn .in_var_ .shrink_to_fit ();
111+ ranging_.col_cost_dn .ou_var_ .shrink_to_fit ();
112+ ranging_.col_bound_up .value_ .shrink_to_fit ();
113+ ranging_.col_bound_up .objective_ .shrink_to_fit ();
114+ ranging_.col_bound_up .in_var_ .shrink_to_fit ();
115+ ranging_.col_bound_up .ou_var_ .shrink_to_fit ();
116+ ranging_.col_bound_dn .value_ .shrink_to_fit ();
117+ ranging_.col_bound_dn .objective_ .shrink_to_fit ();
118+ ranging_.col_bound_dn .in_var_ .shrink_to_fit ();
119+ ranging_.col_bound_dn .ou_var_ .shrink_to_fit ();
120+ ranging_.row_bound_up .value_ .shrink_to_fit ();
121+ ranging_.row_bound_up .objective_ .shrink_to_fit ();
122+ ranging_.row_bound_up .in_var_ .shrink_to_fit ();
123+ ranging_.row_bound_up .ou_var_ .shrink_to_fit ();
124+ ranging_.row_bound_dn .value_ .shrink_to_fit ();
125+ ranging_.row_bound_dn .objective_ .shrink_to_fit ();
126+ ranging_.row_bound_dn .in_var_ .shrink_to_fit ();
127+ ranging_.row_bound_dn .ou_var_ .shrink_to_fit ();
128+ iis_.clear ();
129+
130+ // 3. Shrink standard form LP vectors.
131+ standard_form_cost_.shrink_to_fit ();
132+ standard_form_rhs_.shrink_to_fit ();
133+
134+ // 4. Reset timer clocks (accumulated timing data).
135+ timer_.zeroAllClocks ();
136+
137+ return returnFromHighs (return_status);
138+ }
139+
83140HighsStatus Highs::setOptionValue (const std::string& option, const bool value) {
84141 if (setLocalOptionValue (options_.log_options , option, options_.records ,
85142 value) == OptionStatus::kOk )
0 commit comments