MATLAB: Clear all

clear

I have long script which consumes a lot of memory, so part way through I have included the Clear All function to free up memory so it can continue.
But for some reason it doesn't Clear All the memory properly and ends up running out. When I split up the script and manually Clear All it works.
How can I insure it clears all the memory before proceeding to the next bit of script?
Thanks

Best Answer

Can you plot the code around where you include the "Clear All"? Also, a bit of a long shot here, but you could try pause(1), to keep it from running like crazy.