WIP: Fix memory leak in ProtonPairsToDistanceDrivenProjection#71
WIP: Fix memory leak in ProtonPairsToDistanceDrivenProjection#71acoussat wants to merge 1 commit intoRTKConsortium:mainfrom
Conversation
| protected: | ||
| ProtonPairsToDistanceDrivenProjection(); | ||
| virtual ~ProtonPairsToDistanceDrivenProjection() {} | ||
| virtual ~ProtonPairsToDistanceDrivenProjection() { delete m_ConvFunc; } |
There was a problem hiding this comment.
Thanks (and sorry for the bug). I would move this to AfterThreadedGenerateData since it's been allocated in BeforeThreadedGenerateData.
We could also consider making this LUT a singleton to avoid recreating it if the parameters are not changed but that can be a future work.
There was a problem hiding this comment.
Thanks for the feedback. I moved the deletion to AfterThreadedGenerateData as you suggest in 0e37fec.
5eccaaa to
0e37fec
Compare
|
The CI fails with the following error: The error seems to be linked with RTKConsortium/RTK#901. Do we need to change anything on PCT side? (@SimonRit @axel-grc) |
| ++itCOut; | ||
| } | ||
|
|
||
| delete m_ConvFunc; |
There was a problem hiding this comment.
I don't think it should be in this if (m_ComputeNoise) block. It can be deleted unconditionally I believe.
There was a problem hiding this comment.
Oops, my bad, I was sure I was at the end of the function when I added the line! Fixed in 00909ac.
0e37fec to
00909ac
Compare
I don't know what is the issue but it seems to be on the RTK side, I don't think you should have to change PCT. Maybe something's wrong in these lines. I don't know how to fix it though... Maybe @axel-grc can have a look? |
|
For future reference, we should check this PR again once RTKConsortium/RTK#918 is merged. |
When running a Python script like
the memory consumption increases to a suspiciously high amount (dozens of gigabytes). After careful investigation using valgrind, it seems that the variable
m_ConvFuncused inProtonPairsToDistanceDrivenProjectionis never freed, resulting in a leak of about 50MB per call topct.pctbinning. These 50MB seem to correspond to the Bethe-Bloch LUT.This wasn't a problem when the same script was ran through bash, because (to the best of my understanding) each
pctbinninginvocation resulted in a new sub-process that was deleted after completion. With Python, all the computations are executed in a single Python process, hence the issue.I am not sure if my fix here is really "ITK-like", but as far as I tested this seems to do the trick. I assume that there is a way to fix it that better respects ITK's conventions.