Fix bug in memory metrics collection