nobody seems interested in this question but some extent solved my problem for anyone else facing this issue.
ok - so I missed out a piece of information. The above code was run using the command line because i'm ssh'in to a remote linux box at my office. This crashes even though the machine has massive memory. However, we I run the program using the matlab gui everythings works out fine. No idea why this is the case - maybe there are is a switch need when starting the matlab script?