[SyneRBI/SIRF] Memory not freed up after deleting linear acquisition model (Issue #1377)

1 view
Skip to first unread message

hsw43

unread,
Feb 26, 2026, 12:44:00 PMFeb 26
to SyneRBI/SIRF, Subscribed
hsw43 created an issue (SyneRBI/SIRF#1377)

I noticed a memory leak while running my algorithm over all dataset in one job. After investigating, I think I have identified that it was due to memory built up after calling the get_linear_acquisition_model function.

I tried computing the forward projection of the linear model with the following options:

  1. acq_linear = self._acq_models[i].get_linear_acquisition_model()
    fwd = acq_linear.forward(self._x_one)
    del acq_linear

  2. fwd = self._acq_models[i].forward(self._x_one) - self._acq_models[i].get_constant_term()

The figure bellow shows the memory usage (after running a few dataset) of the two options. The purple one shows option one and the red one shows option 2.

Screenshot.2026-02-13.173404.png (view on web)


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1377@github.com>

Kris Thielemans

unread,
Feb 26, 2026, 12:45:20 PMFeb 26
to SyneRBI/SIRF, Subscribed
KrisThielemans left a comment (SyneRBI/SIRF#1377)

@evgueni-ovtchinnikov how does get_linear_acquisition_model() handle shared ownership?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1377/3968179059@github.com>

Evgueni Ovtchinnikov

unread,
Mar 19, 2026, 2:25:56 PMMar 19
to SyneRBI/SIRF, Subscribed
evgueni-ovtchinnikov left a comment (SyneRBI/SIRF#1377)

how does get_linear_acquisition_model() handle shared ownership?

@KrisThielemans underlying C++ code just copies some shared pointers, no data allocated.

The reason for the memory leak could be the absence of __del__ in SIRF's base class AcquisitionModel.

@hsw43 can you please add to class AcquisitionModel (in SIRF file STIR.py) this method:

    def __del__(self):
        if self.handle is not None:
            pyiutil.deleteDataHandle(self.handle)

and then build SIRF and repeat your memory leak tests?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1377/4092354476@github.com>

Kris Thielemans

unread,
Mar 20, 2026, 3:44:48 AMMar 20
to SyneRBI/SIRF, Subscribed
KrisThielemans left a comment (SyneRBI/SIRF#1377)

Thanks @evgueni-ovtchinnikov.

@hsw43 I'm not sure if you have time for this, and rebuilding SIRF is probably out of the question as the docker image doesn't contain the necessary files. However, you can just edit the SIRF.py in your system (if you cannot find it, in python, something like this can work "import sirf.STIR; sirf.STIR.file").

However, @evgueni-ovtchinnikov it shouldn't be too hard to replace this yourself. Just put a loop around a all of the code above (adding an actual call to acq_model.forward) and monitor memory via a system monitor, or possibly

import psutil
ram = psutil.virtual_memory()
print("RAM used (GB):", round(ram.used / 1e9, 2))


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1377/4096314500@github.com>

Evgueni Ovtchinnikov

unread,
Mar 20, 2026, 7:18:59 AMMar 20
to SyneRBI/SIRF, Subscribed
evgueni-ovtchinnikov left a comment (SyneRBI/SIRF#1377)

I do not have self._acq_models[i] and self._x_one I am afraid.

Besides, rebulding SIRF on our SIRF VM after missing __del__ is added should just copy STIR.py to ~/devel/install/python/sirf.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1377/4097334031@github.com>

Kris Thielemans

unread,
Mar 20, 2026, 10:43:48 AMMar 20
to SyneRBI/SIRF, Subscribed
KrisThielemans left a comment (SyneRBI/SIRF#1377)

I do not have self._acq_models[i] and self._x_one I am afraid.

the memory leak should happen with any acq_model as long as there's a constant term. x_one is just any image (actually, filled with 1, but not important for this test)

Besides, rebulding SIRF on our SIRF VM after missing __del__ is added should just copy STIR.py to ~/devel/install/python/sirf.

Sure but I doubt @hsw43 is using the VM (our latest is 3.8 anyway). Fairly sure he was using the petric2 docker image (which doesn't contain sources).


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1377/4098531573@github.com>

hsw43

unread,
Mar 20, 2026, 10:56:05 AMMar 20
to SyneRBI/SIRF, Subscribed
hsw43 left a comment (SyneRBI/SIRF#1377)

Sorry for the delay.

I actually build SIRF following this (with Kris's help)
I have found STIR.py and added the __del__ method to the AcquisitionModel class.

I wonder if I need to rebuild SIRF before running my memory tests? Or is it fine to run them directly?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1377/4098669133@github.com>

Kris Thielemans

unread,
Mar 20, 2026, 11:03:28 AMMar 20
to SyneRBI/SIRF, Subscribed
KrisThielemans left a comment (SyneRBI/SIRF#1377)

great. You don't need to rebuild SIRF, but you then need to be careful which SIRF.py you modify. (the one in sources/SIRF isn't used by Python). Obviously, you can just check the class definition to see if everything is fine.

thanks!


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1377/4098761079@github.com>

Evgueni Ovtchinnikov

unread,
Mar 20, 2026, 11:10:48 AMMar 20
to SyneRBI/SIRF, Subscribed
evgueni-ovtchinnikov left a comment (SyneRBI/SIRF#1377)

@hsw43 On SIRF VM I do this:

sirfuser@vagrant:~$ cd devel/buildVM/builds/SIRF/build/
sirfuser@vagrant:~/devel/buildVM/builds/SIRF/build$ make install

Since you just edited a Python script SIRF.py, this actually simply copies this script to ~/devel/install/python/sirf.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1377/4098833861@github.com>

hsw43

unread,
Mar 23, 2026, 6:56:35 AMMar 23
to SyneRBI/SIRF, Subscribed
hsw43 left a comment (SyneRBI/SIRF#1377)
image.png (view on web)

Just ran a quick test with the 2 most memory intensive datasets (Vision600_ZrNEMA and Vision600_Hoffman). I was able to run the Hoffman after ZrNEMA (which I could not if I used get_linear_acquisition_model() without adding the __del__ method), might be a good sign.

However, it seems that a small portion of memory is still in used. Need to run on all dataset to confirm.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1377/4109721650@github.com>

hsw43

unread,
Mar 25, 2026, 6:18:56 AM (13 days ago) Mar 25
to SyneRBI/SIRF, Subscribed

I just rerun SPDDY on all the datasets. I was able to run everything with one call.
Although there is a small discrepancy of available memory going from one dataset to another, I think the memory leak due to calling get_linear_acquisition_model has been fixed.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1377/4125338832@github.com>

Kris Thielemans

unread,
Mar 25, 2026, 6:59:01 AM (13 days ago) Mar 25
to SyneRBI/SIRF, Subscribed
KrisThielemans left a comment (SyneRBI/SIRF#1377)

Excellent. Thanks a lot for testing!

@evgueni-ovtchinnikov please create a PR with the fix (and merge it :-))


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1377/4125604919@github.com>

Evgueni Ovtchinnikov

unread,
Mar 25, 2026, 11:50:13 AM (13 days ago) Mar 25
to SyneRBI/SIRF, Subscribed

Closed #1377 as completed via #1387.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issue/1377/issue_event/23897087750@github.com>

Reply all
Reply to author
Forward
0 new messages