Project

General

Profile

Bug #1331

Memory leak when using SciFiPlane

Added by Rogers, Chris over 10 years ago. Updated over 10 years ago.

Status:
Open
Priority:
Normal
Category:
Tracker
Target version:
Start date:
14 August 2013
Due date:
% Done:

0%

Estimated time:
Workflow:
In Development

Description

There is no way to use SciFiPlane to generate a plane without also making a memory leak.

  • When I place physiCore Geant4 takes ownership of the memory
  • When I attempt to delete SciFiPlane it tries to delete physiCore.

Currently, SciFiPlane never gets deleted. But this is clearly a memory leak.

#1

Updated by Dobbs, Adam over 10 years ago

  • Assignee changed from Dobbs, Adam to Heidt, Christopher

Thanks for heads up, reassigning to Chris Heidt.

#2

Updated by Heidt, Christopher over 10 years ago

I'm looking at this now.

#3

Updated by Heidt, Christopher over 10 years ago

  • Workflow changed from New Issue to Under Test

Looks like problem was from MICEDetectorConstruction.cc

if( detector == "SciFiPlane" )
{
SciFiPlane* plane = new SciFiPlane( mod, mat, moth );
logic = plane->logicalCore();
place = plane->placementCore();
}

now looks like:

if( detector == "SciFiPlane" )
{
SciFiPlane* plane = new SciFiPlane( mod, mat, moth );
logic = plane->logicalCore();
place = plane->placementCore();
delete plane;
}

This should take care of it. Change is uploaded to tracker development branch.

#4

Updated by Rogers, Chris over 10 years ago

No that's the whole point.

      delete plane;

You have now deleted logic and place, which GEANT4 thinks it owns. So when GEANT4 cleans up, it will also delete logic and place - segmentation fault.

#5

Updated by Dobbs, Adam over 10 years ago

I'll try and expand a bit. Looking at the previous code snippet etc, we want to remove SciFiPlane to prevent a memory leak. However the SciFiPlane destructor:

SciFiPlane::~SciFiPlane() {
  delete physiDoublet;
  delete physiCore;

  delete solidDoublet;
  delete solidCore;

  delete logicDoublet;
  delete logicCore;
}

deletes the logicalCore and placementCore for which we have just passed ownership to GEANT4, so when GEANT4 comes to use or delete them, we get a seg fault.

I have had a go at sorting this too by adding flags to SciFiPlane, such that the we can turn on or off which members it deletes. For the present however I have been thwarted by some darknesses in SciFiPlane. In particular:

  • The constructor does virtually all of the work; constructor should not do large amounts of work for various reasons, so we should move this to an Initialise function or similar
  • The memory management is confusing e.g.
physiDoublet = placeCore = new G4PVPlacement(pRot, mod->position(),
                                               logicDoublet, doubletName,
                                               mlv->GetLogicalVolume(),
                                               false, 0);

why do we have two member variables of different pointer types pointing to the same block of memory? Also various things we new are passed to other objects and the final ownership is not apparent.

  • I have been seeing strange seg faults sometimes when deleting logicDoublet

I will keep poking; Chris H, if you can do the same, and we'll see what we can come up with...

#6

Updated by Dobbs, Adam over 10 years ago

Fix is now in the tracker devel branch (revision 1030), using the method outlined above. I would like some tidying done on SciFiPlane class before merging into trunk...

#7

Updated by Dobbs, Adam over 10 years ago

  • Assignee changed from Heidt, Christopher to Rogers, Chris
  • Workflow changed from Under Test to In Development

Update - deleting the SciFiPlane even if logicalCore and placementCore are preserved still seems to break the reconstruction (no SciFiDigits get generated, need to run more checks to see if this is really happening).

Also, not sure why this is seen as a tracker issue only, all the other detectors listed there look like they behave identically:

    if( detector == "SciFiPlane" )
    {
      SciFiPlane* plane = new SciFiPlane( mod, mat, moth );
      logic = plane->logicalCore();
      place = plane->placementCore();
    }
    else if ( detector == "KLGlue" )
    {
      KLGlue* glue = new KLGlue( mod, mat, moth);
      logic = glue->logicalStrip();
      place = glue->placementStrip();
    }
    else if ( detector == "KLFiber" )
    {
      KLFiber* fiber = new KLFiber( mod, mat, moth);
      logic = fiber->logicalFiber();
      place = fiber->placementFiber();
    }
    else if ( detector == "CkovMirror" )
    {
      CkovMirror* mirror = new CkovMirror( mod, mat, moth);
      logic = mirror->logicalMirror();
      place = mirror->placementMirror();
    }

Bouncing back to Chris R for advice before proceeding.

#8

Updated by Rogers, Chris over 10 years ago

  • Assignee changed from Rogers, Chris to Heidt, Christopher

deleting the SciFiPlane even if logicalCore and placementCore are preserved still seems to break the reconstruction

How interesting. I wonder what has happened there...

Also, not sure why this is seen as a tracker issue only, all the other detectors listed there look like they behave identically:

So everyone has a bug. I have found a bug for you. You are grateful, no?

Also available in: Atom PDF