Adds tests for mem limits.

All tests pass.
valgrind reports 0 errors.