[ITK] [ITK-users] R-SimpleITK memory management
Yaniv, Ziv Rafael (NIH/NLM/LHC) [C]
zivrafael.yaniv at nih.gov
Wed Jul 6 11:23:37 EDT 2016
Hi Mathew,
Can you provide a concise example so that we can recreate the problem? I
tried the trivial thing with the code we were previously discussing, just
repeatedly running it in a loop and the memory useage is as expected,
doesn¹t change after initial run, code below:
library(SimpleITK)
library(pryr)
for(i in 1:100)
{
print(mem_used())
image <- ReadImage("training_001_ct.mha")
segmented_image <- image>700
segmented_label <- 1
lisf <- LabelIntensityStatisticsImageFilter()
invisible(lisf$Execute(segmented_image, image))
print(mem_used())
}
When I ran this in R studio the memory usage was higher, but still
consistent. Apparently R studio also keeps a reference to every object
created on the command line (Hadly Wickham¹s book on Advanced R, memory
management http://adv-r.had.co.nz/memory.html).
Ziv
On 7/6/16, 9:55 AM, "Mathew Guilfoyle" <mrguilfoyle at gmail.com> wrote:
>I'm processing a large number of CT scans using R wrapped SimpleITK
>(some filtering and then registration before a segmentation). I'm
>running R within RStudio on OS X 10.11
>
>I'm running into memory problems with long processing runs. Though in
>the R loops I reassign new images to the same R variable the
>underlying C++ objects do not seem to get deleted but accumulate on
>each loop - I can see steadily rising memory usage in Activity Monitor
>until R/RStudio crashes. I have tried explicitly deleting the
>temporary images during each loop and calling the R garbage collector
>(gc()), but it doesn't seem to have an effect. If I restart the R
>session then the memory is cleared.
>
>My understanding was that the C++ objects would get garbage collected
>once all pointers are removed but this doesn't seem to happen. Is
>there a method to explicitly delete the C++ image objects so I can
>manage the memory usage myself?
>
>Cheers
>_____________________________________
>Powered by www.kitware.com
>
>Visit other Kitware open-source projects at
>http://www.kitware.com/opensource/opensource.html
>
>Kitware offers ITK Training Courses, for more information visit:
>http://www.kitware.com/products/protraining.php
>
>Please keep messages on-topic and check the ITK FAQ at:
>http://www.itk.org/Wiki/ITK_FAQ
>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/insight-users
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php
Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
More information about the Community
mailing list