From a587b140068de141b808a4b3b5aa77c0e3cc0bb5 Mon Sep 17 00:00:00 2001 From: Tomonobu Saito Date: Fri, 4 Oct 2019 17:30:35 +0900 Subject: [PATCH] destruct static vector and unorderd_map when last RasterContainer is destructed. --- include/extractor/raster_source.hpp | 10 +++++++++- src/extractor/raster_source.cpp | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/extractor/raster_source.hpp b/include/extractor/raster_source.hpp index 633c0c661..f85144a55 100755 --- a/include/extractor/raster_source.hpp +++ b/include/extractor/raster_source.hpp @@ -126,7 +126,14 @@ class RasterSource class RasterContainer { public: - RasterContainer() = default; + RasterContainer() { ++count; } + ~RasterContainer() { + --count; + if (0 == count) { + LoadedSources.clear(); + LoadedSourcePaths.clear(); + } + } int LoadRasterSource(const std::string &path_string, double xmin, @@ -143,6 +150,7 @@ class RasterContainer private: static std::vector LoadedSources; static std::unordered_map LoadedSourcePaths; + static int count; }; } } diff --git a/src/extractor/raster_source.cpp b/src/extractor/raster_source.cpp index befae77b7..8c62cc8b2 100755 --- a/src/extractor/raster_source.cpp +++ b/src/extractor/raster_source.cpp @@ -81,6 +81,7 @@ RasterDatum RasterSource::GetRasterInterpolate(const int lon, const int lat) con // static member of Raster Container std::vector RasterContainer::LoadedSources; std::unordered_map RasterContainer::LoadedSourcePaths; +int RasterContainer::count = 0; // Load raster source into memory int RasterContainer::LoadRasterSource(const std::string &path_string,