MathCancer / PhysiCell

PhysiCell: Scientist end users should use latest release! Developers please fork the development branch and submit PRs to the dev branch. Thanks!
http://PhysiCell.org
137 stars 92 forks source link

PhysiCell::Cell_Definition possibly memory leaking #263

Open elmbeech opened 3 months ago

elmbeech commented 3 months ago

I get a Segmentation fault (core dumped), if I try to generate a second instance of a Cell_Definition. Reading up on this, this potentially points to a memory leaking.

Minimal example:

  1. rest to a fresh PhysiCell installation.

    make clean reset
    make template
  2. add the following line to custom_modules/custome.cpp.

    PhysiCell::Cell_Definition cell_defaults_two;
  3. compile and run the template project.

    make 
    ./project

I will have to study the code in deep and use a debugger to resolve this issue.

rheiland commented 3 months ago

Your reason for wanting to create a second instance of a Cell_Definition escapes me, but just as an academic exercise, I took a closer look and created a repo to demonstrate. Do NOT do a make reset, just make and run project. Take a look at the modified/simplified main.cpp and the custom.cpp. Bottom line: the cell_defaults instance (in core/PhysiCell_cell.cpp) is quite special and has a long history which includes how cell definitions have evolved. Nevertheless, hopefully this repo is instructive: https://github.com/rheiland/second_cell_defaults_instance

Having said that, yes, I encourage you (and anyone else) to use a debugger to track down where segfaults occur. In this case, it's not a memory leak.