The above command gives you reports of free ram space at every second.
So you can run it in one terminal and in another terminal you can run your programme. If you see that there is a spike in used ram space and getting the  error, then probably there is a memory problem.