Fixed a race condition in measuring memory usage.