When running 250000 function iterations for function 12 I have noticed that the R process starts to eat around 30GB of memory (12GB of real ram and around 18GB of swap). This problem didn't show up with functions 6-11. I will continue testing function 19-24 and after it I'll get back to function 12 to try to figure out the problem (although my knowledge of coding extensions in C for R is non-existent).