I fixed a memory leak caused by the wrapper of the GaussianProcess c++ class which created internal memory. In cross validation I created this class once at the beginning of the loop then in the loop continually called the c++ function that called malloc. By simpling explicitly deleting the c++ memory at each step in the loop the memory leak disappeared.