Memory leakage with GetDVHCumulativeData

Sep 23, 2016 at 3:13 PM
I am writing a simple stand-alone ESAPI app to iterate through a number of patients and then extract DVH data for a given structure to a text file. In the source file, the main method calls a static method for each external beam treatment plan which includes a call to GetDVHCumulativeData() to obtain the curve data. However, upon running, there is significant memory leakage, which eventually brings the program to snails pace after a few patients, presumably due to thrashing.

Checking the code, I found that the memory leak exists if I simply include the following line in the static method:

DVHData dvhAbsolute = selectedPlan.GetDVHCumulativeData(structureEsophagus, DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, 0.001);

I am using GetDVHCumulativeData because some of the plans are sum plans, so I cannot use the PlanSetup.GetVolumeAtDose() method (which will not give any memory leak in my code).

I am using Visual Studio Community 2015 with Eclipse v11 on a 64-bit Windows-7 system. Could anyone help with this problem?
Sep 23, 2016 at 3:35 PM
I've had similar memory leak problems when dealing with DVH data. One work-around is to dispose of the Eclipse application after processing a few patients, then create it again and process some more, etc.
Marked as answer by Chunhui on 9/23/2016 at 9:59 AM
Sep 23, 2016 at 3:49 PM
Thanks for reporting this issue.

redcurry, do you know if this is a problem in v13.6?
Sep 23, 2016 at 4:53 PM
We are investigating and will report back if we can reproduce this. Here are a few things to pay attention to:
1) [v11] There are known performance issues when iterating over courses that have many plans. V11 performs a full load of every plan in the course while you are iterating. This is fixed in v13+ so that a full plan load is not done while iterating but later when you access details of a plan.
2) [all versions] Multithreading w/ ESAPI - ESAPI does not allow reentrant calls.
3) [all versions] Use 64 bit instead of 32 bit to avoid memory issues.

Also see these two discussions:
Sep 23, 2016 at 6:11 PM
Thanks for the suggestion by Carlos. It works. I had my program dispose of the ESAPI Application instance in each iteration. The memory used by GetDVHCumulativeData() is released and the program runs smoothly. There will probably be some overhead with constant Application creation and disposal, but it is not noticeable.
Sep 23, 2016 at 6:46 PM
Wayne, I don't know if this is still a problem in v. 13.6.

Chunhui, if you want to reduce some of the overhead, you could process several patients (perhaps 10 or 20) before re-creating the Application. You'll have to run some performance tests to figure out the actual number of patients to process each iteration. I'm glad it's working!