Sierra Toolkit  Version of the Day
stk_mesh/stk_mesh/base/Trace.cpp
1 #include <stk_mesh/base/Trace.hpp>
2 #include <stk_mesh/base/EntityKey.hpp>
3 #include <stk_mesh/base/Types.hpp>
4 
5 #include <stk_util/environment/ReportHandler.hpp>
6 
7 #include <set>
8 
9 namespace stk_classic {
10 namespace mesh {
11 
12 //We used to store a static vector 'watch_vector', but its
13 //contents (pointers) didn't get deleted which resulted in
14 //memory leaks.
15 //Instead, we now wrap the watch_vector in this 'WatchVectorHolder'
16 //struct, which has a destructor which cleans up the contents
17 //of watch_vector. This eliminates the memory leaks.
18 struct WatchVectorHolder {
19  WatchVectorHolder() : watch_vector() {}
20  ~WatchVectorHolder()
21  {
22  for(std::vector<Watch*>::iterator it=watch_vector.begin();
23  it!=watch_vector.end(); ++it) {
24  delete *it;
25  }
26  }
27 
28  std::vector<Watch*> watch_vector;
29 };
30 
31 std::vector<Watch*>& watch_vector()
32 {
33  static WatchVectorHolder watch_vector_holder;
34  return watch_vector_holder.watch_vector;
35 }
36 
37 } // namespace mesh
38 } // namespace stk_classic
Sierra Toolkit.