If you want to use your raspberry pi in headless mode (no monitor connected), you can decrese the number of memory from your gpu to gain more free memory.
Open the file "/boot/config.txt" and search for something like "gpu_mem_". The advice is to set it to something like "64" or "48". Otherwise it is possible that your pi will not boot.
I really and a long time thought about a problem with a cronjob php skript. This script has to run long (in php terms, very long or lets say longer than one hour). I implemented a lot of verbose output and figured out that the script is using more and more memory. Thats why i implemented the using of "gc_enable()" and "gc_collect_cycles" without less luck. After a while i tackeld it down to my favorit used php orm mapper called propel. After having "propel" in my mind, the instance pooling comes in my mind and the final fix was reachable.
Add the code on top to your script and the memoryusage should not increase anymore (or you have another memory hole ;-)).