Skip to content

SuperDropletsMoist leaks its particle container #3035

@asalmgren

Description

@asalmgren

Location

  • Source/Microphysics/SuperDropletsMoist/ERF_SuperDropletsMoist.H:135-136,415
  • Source/Microphysics/SuperDropletsMoist/ERF_SuperDropletsMoistInit.cpp:169-175

Problem

SuperDropletsMoist allocates m_super_droplets with new:

m_super_droplets = new SuperDropletPC(...);

but uses a default destructor and never deletes it.

Why this is a bug

This is an ownership/lifetime bug: each model instance leaks one SuperDropletPC and associated allocations. In long-running workflows with reinitialization/restart cycles or repeated object construction, this causes avoidable memory growth.

Suggested patch

Use RAII ownership (std::unique_ptr) for m_super_droplets.

--- a/Source/Microphysics/SuperDropletsMoist/ERF_SuperDropletsMoist.H
+++ b/Source/Microphysics/SuperDropletsMoist/ERF_SuperDropletsMoist.H
@@
-        inline virtual ERFPC* getParticleContainer() override
+        inline virtual ERFPC* getParticleContainer() override
         {
-            return m_super_droplets;
+            return m_super_droplets.get();
         }
@@
-        SuperDropletPC* m_super_droplets;
+        std::unique_ptr<SuperDropletPC> m_super_droplets;
--- a/Source/Microphysics/SuperDropletsMoist/ERF_SuperDropletsMoistInit.cpp
+++ b/Source/Microphysics/SuperDropletsMoist/ERF_SuperDropletsMoistInit.cpp
@@
-    m_super_droplets = new SuperDropletPC ( a_geom,
-                                            a_cons_vars.DistributionMap(),
-                                            a_cons_vars.boxArray(),
-                                            m_species,
-                                            m_aerosols,
-                                            m_dt,
-                                            m_name );
+    m_super_droplets = std::make_unique<SuperDropletPC> ( a_geom,
+                                                           a_cons_vars.DistributionMap(),
+                                                           a_cons_vars.boxArray(),
+                                                           m_species,
+                                                           m_aerosols,
+                                                           m_dt,
+                                                           m_name );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions