|
Sierra Toolkit
Version of the Day
|
00001 #include <stk_mesh/base/Trace.hpp> 00002 #include <stk_mesh/base/EntityKey.hpp> 00003 #include <stk_mesh/base/Types.hpp> 00004 00005 #include <stk_util/environment/ReportHandler.hpp> 00006 00007 #include <set> 00008 00009 namespace stk_classic { 00010 namespace mesh { 00011 00012 //We used to store a static vector 'watch_vector', but its 00013 //contents (pointers) didn't get deleted which resulted in 00014 //memory leaks. 00015 //Instead, we now wrap the watch_vector in this 'WatchVectorHolder' 00016 //struct, which has a destructor which cleans up the contents 00017 //of watch_vector. This eliminates the memory leaks. 00018 struct WatchVectorHolder { 00019 WatchVectorHolder() : watch_vector() {} 00020 ~WatchVectorHolder() 00021 { 00022 for(std::vector<Watch*>::iterator it=watch_vector.begin(); 00023 it!=watch_vector.end(); ++it) { 00024 delete *it; 00025 } 00026 } 00027 00028 std::vector<Watch*> watch_vector; 00029 }; 00030 00031 std::vector<Watch*>& watch_vector() 00032 { 00033 static WatchVectorHolder watch_vector_holder; 00034 return watch_vector_holder.watch_vector; 00035 } 00036 00037 } // namespace mesh 00038 } // namespace stk_classic