lesgourg / class_public

Public repository of the Cosmic Linear Anisotropy Solving System (master for the most recent version of the standard code; GW_CLASS to include Cosmic Gravitational Wave Background anisotropies; classnet branch for acceleration with neutral networks; ExoCLASS branch for exotic energy injection; class_matter branch for FFTlog)
223 stars 291 forks source link

Memory leaks in python wrapper #106

Open sthagstotz opened 8 years ago

sthagstotz commented 8 years ago

Hi, I have a likelihood code for Montepython which calls cosmo.get_transfer() quite often, and the chains use more and more memory until they crash.

I think the problem is in the function definition in classy.pyx: we have data = <double*>malloc(sizeof(double)*size_ic_data*ic_num) but data is never freed, and uses memory until python exits. I think there should be a free(data) free(titles) before the function ends. The same is true for a lot of other functions like get_background(), get_thermodynamics() or pk().

Even then there is a (way slower) memory buildup, but I'm not sure what's causing it. Did anyone have similar problems?

Best, Steffen

nbellomo commented 8 years ago

Hello Steffen, I was working with Montepython too and I had the same problem of memory leak with the pk() function. In my case the problem was related to the *pk_ic pointer and just adding a free(pk_ic) was enough to avoid the memory leak. So far I haven't noticed any other memory build up. Hope that it helps! Best, Nicola