How to manually release memory of Image after data was loaded? #525
-
Suppose I created a list of for a in im_list:
for b in im_list:
if a == b: continue
# Do somthing with a & b
# need to release memory used by b
... So I only need simultaneously a & b, but after the data was loaded in the inner loop, it persist and there is a waste of memory. Is there a way I can release the memory and revert the What I've tried: del b # in inner loop, doesn't release mem
del b.data # can't delete attribute Cheers |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, @alabamagan. This is probably because instances in import torchio as tio
subjects = [tio.Subject(im=im) for im in im_list]
dataset = tio.SubjectsDataset(subjects)
for sub1 in dataset:
for sub2 in dataset:
if compare(sub1.im, sub2.im):
do_sth() |
Beta Was this translation helpful? Give feedback.
Hi, @alabamagan.
This is probably because instances in
a
andb
are repeated, so even if you delete them withdel
, you will still be keeping a pointer to them in one of the lists and memory will not be released. A possible solution is iterating overSubjectsDataset
, which makes copies of the subjects. Then, maybe you can use the path of the image or the tensor data to compare two images.