# Clearing memory of a subkernel in a Do loop

I have a Do loop, which saves data directly to a .txt file. However when I leave it running for long periods of time the RAM starts to run out till finally my laptop crashes. I've read similar posts on here but nothing seems to have worked.

After each run of the Do loop, I no longer need the data because it has been saved in a .txt file. This means I don't require Mathematica to use up my RAM remembering it... but I can't get it to stop!

I tried putting ClearSystemCache[] inside the Do loop at the end but this didnt work. I read somewhere that this could be because I need to clear the memory of the individual subkernels.

What is meant by subkernel? I run ParallelEvaluate[] and it launches four kernels, one for each CPU. Are these 4 kernels called subkernels? If so what is 'sub' about them? But the main question is how do i go about clearing the memory of the subkernals?

My set up is

ParallelEvaluate[
Do[
(bulk of formulae)
If[ (condition), PutAppend[ ]     ]
]
]


I have tried putting

ParallelEvaluate[
Do[
(bulk of formulae)
If[ (condition), PutAppend[ ]     ]
ClearSystemCache[]
]
]


However this doesnt seem to work.

I've also tried:

• putting \$HistoryLength = 0; at the start of the Do loop (doesn't change anything)

• putting Clear["Global*"]

• putting Remove["Global*"] inside end of Do loop (gives an error)

If someone could explain how to clear memory of subkernels and/or give any other suggestions that would be great. Thanks

-
Try Unprotect[Out]; Clear[Out];. –  chyaong Sep 10 '13 at 9:06
@kingmonkeywoman Are you using Module for defining your functions? In afirmative case, this might be the issue. @chyaong in such case, your suggestion won't work, because of the bug described in stackoverflow.com/questions/6867892/… –  fcpenha Apr 9 '14 at 12:21