diff --git a/python/adjoint/optimization_problem.py b/python/adjoint/optimization_problem.py index c871cf6ba..a700d49bc 100644 --- a/python/adjoint/optimization_problem.py +++ b/python/adjoint/optimization_problem.py @@ -304,6 +304,12 @@ def calculate_gradient(self): for ar in range(len(self.objective_functions)) ] + for dri in range(self.num_design_regions): + for i in range(3): + # note that dft_fields::remove calls delete on its chunks, and the + # destructor ~dft_chunk automatically removes it from the fields object + self.forward_design_region_monitors[dri][i].remove() + # Cleanup list of lists if len(self.gradient) == 1: self.gradient = self.gradient[0] # only one objective function diff --git a/src/meepgeom.cpp b/src/meepgeom.cpp index 15fa04076..b9a8feedc 100644 --- a/src/meepgeom.cpp +++ b/src/meepgeom.cpp @@ -2999,7 +2999,6 @@ void material_grids_addgradient(double *v, size_t ng, size_t nf, for (int i = 0; i < 3; i++) { for (int ii = 0; ii < adjoint_dft_chunks[i].size(); ii++) { delete adjoint_dft_chunks[i][ii]; - delete forward_dft_chunks[i][ii]; } }