I do this as I described in an old post here. In addition just add something like
# MEMORY CONSUMPTION TEST
function memOK( mb::Int, memlimit::Int )
if( mb > memlimit )
println("### Memory-usage too high: $mb (MB)")
return false
else
return true
end
end
and terminate your program if the latter function returns false
.