I am a complete newbie to coding, so all I say might me BS. But I will still say it
When you allocate memory, you should always free it at the end of the program right?
Also what are you iterating so much(well, not that much)? Could you give us the code so we can look at it and maybe search for a more eficient algorithm?
In college, I have done stupid recursive factorials programs with Pascal, they couldnt go past 15! . So if your algorithm is factorial, that might be the problem!