diff --git a/include/openmc/tallies/tally_filter.h b/include/openmc/tallies/tally_filter.h index d6cf72cd9..f6118f92f 100644 --- a/include/openmc/tallies/tally_filter.h +++ b/include/openmc/tallies/tally_filter.h @@ -51,5 +51,9 @@ public: virtual void initialize() = 0; }; +//============================================================================== + +extern "C" void free_memory_tally_c(); + } // namespace openmc #endif // OPENMC_TALLY_FILTER_H diff --git a/src/tallies/tally_filter.cpp b/src/tallies/tally_filter.cpp index 660178cbf..65ba03076 100644 --- a/src/tallies/tally_filter.cpp +++ b/src/tallies/tally_filter.cpp @@ -15,6 +15,22 @@ namespace openmc { std::vector filter_matches; std::vector tally_filters; +//============================================================================== +// Non-member functions +//============================================================================== + +void +free_memory_tally_c() +{ + #pragma omp parallel + { + filter_matches.clear(); + } + + for (TallyFilter* filt : tally_filters) {delete filt;} + tally_filters.clear(); +} + //============================================================================== // Fortran compatibility functions //============================================================================== diff --git a/src/tallies/tally_header.F90 b/src/tallies/tally_header.F90 index 367214a93..b0532a40c 100644 --- a/src/tallies/tally_header.F90 +++ b/src/tallies/tally_header.F90 @@ -412,6 +412,13 @@ contains !=============================================================================== subroutine free_memory_tally() + interface + subroutine free_memory_tally_c() bind(C) + end subroutine free_memory_tally_c + end interface + + call free_memory_tally_c() + n_tallies = 0 if (allocated(tallies)) deallocate(tallies) call tally_dict % clear()