sot / chandra_time

Convert between various time formats relevant to Chandra.
https://sot.github.io/Chandra.Time
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

Memory leak in C++ code #31

Closed mbaski closed 5 years ago

mbaski commented 5 years ago

Calls to Chandra.Time.convert leak memory significantly enough to cause memory issues when using the FOT MATLAB Tools (specifically the Xija thermal models which use Chandra.Time to convert between MATLAB Tools times and Xija model times). The following conversion loop leaks around 2 MB of memory a second on a GRETA workstation:

import Chandra.Time  
test_vals = range(100000)  
for i in range(20)  
   a=Chandra.Time.convert(test_vals,fmt_in="secs",sys_in="utc",fmt_out="secs",sys_out="tt")

This memory leak is caused by the lack of "delete" calls in the C++ code after creating new objects with "new" statements. Specifically, adding the following statement after line 166 of axTime3.cc eliminates the memory leak experienced by the MATLAB Tools when running the Xija thermal models:

delete(T);
taldcroft commented 5 years ago

Amazing sleuthing! Will fix.