Skip to content

Try to plug memory leaks in TRT_BaseElement ATLASRECTS-5271

This is my take on ATLASRECTS-5271 . Not sure if it will work as is

  • Basically changing
-    // Amg cache for the straw surfaces 
-    mutable std::atomic<std::vector<Trk::StraightLineSurface*>*> m_strawSurfaces{};
-    mutable std::atomic<std::vector<SurfaceCache*>*> m_strawSurfacesCache{};
-    
+
+    // Amg cache for the straw surfaces
+    CxxUtils::CachedUniquePtrT<
+      std::vector<std::unique_ptr<Trk::StraightLineSurface>>>
+      m_strawSurfaces{};
+
+    CxxUtils::CachedUniquePtrT<std::vector<std::unique_ptr<SurfaceCache>>>
+      m_strawSurfacesCache{};
  • Also update etc can not really be easily be made "const" in MT and actually they do not need be.

I have some question marks on the thread safety part e.g

-      Amg::Transform3D* sTransform = new Amg::Transform3D(Amg::CLHEPTransformToEigen(cStrawTransform));
-      Amg::Vector3D*    sCenter    = new Amg::Vector3D(sTransform->translation());
-
-      // create the surface cache & fill it
-      SurfaceCache* sSurfaceCache     = new SurfaceCache(sTransform, sCenter, 0, 0);
-      (*m_strawSurfacesCache)[straw]  = sSurfaceCache;

now is

+        Amg::Transform3D* sTransform = new Amg::Transform3D(Amg::CLHEPTransformToEigen(cStrawTransform));
+        Amg::Vector3D* sCenter = new Amg::Vector3D(sTransform->translation());
+        // create the surface cache & fill it
+        (*m_strawSurfacesCache)[straw] = std::make_unique<SurfaceCache>(sTransform, sCenter, nullptr, nullptr);

so should not leak , but not sure what would happen or was happening if 2 threads try to set something for the same straw. Since I was after the mem leaks here, I did not change the logic here.... e.g the diff above is migrating to unique_ptr

Anyhow , let me mentiong @carquin , @amete ,@wlampl , @oda , as if this does not work they might want to have another take...

Edited by Christos Anastopoulos

Merge request reports