From dc654e0770e7f990a422508d3ed8df73104881d4 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Thu, 12 Dec 2024 14:36:35 -0500 Subject: [PATCH] Clean up var memory in laplace_sample --- src/stan/services/optimize/laplace_sample.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/stan/services/optimize/laplace_sample.hpp b/src/stan/services/optimize/laplace_sample.hpp index 600fc52cd5..423c8c8ea4 100644 --- a/src/stan/services/optimize/laplace_sample.hpp +++ b/src/stan/services/optimize/laplace_sample.hpp @@ -121,6 +121,8 @@ void laplace_sample(const Model& model, const Eigen::VectorXd& theta_hat, double log_p; if (calculate_lp) { + // clean up created vars after scope exit + stan::math::nested_rev_autodiff stack; log_p = log_density_fun(unc_draw).val(); } else { log_p = std::numeric_limits::quiet_NaN();