title: In Ruby, what is stored on the stack?
body: <p>Does Ruby allocate everything on the heap or are there any instances where something is stored on the stack? I'm under the impression that all variables are essentially on the stack and contain a transparent reference to an object on the heap. Am I correct in this thinking? Is this implementation specific?</p>
  
  <p>Also, if it is the case that variables are allocated on the stack and merely contain hidden pointers, how many bytes do the variables themselves (disregarding the objects they point to) consume?</p>
  
  <p>Edit:</p>
  
  <p>This question was asked because I was trying to figure out whether a fiber's 4kB stack limit would be an issue in <a href="https://stackoverflow.com/q/13638503/509271">this question</a>. It seems as though (with MRI 1.9.3) that each variable itself consumes one byte and there's a slight overhead associated with the fiber which reduces the available stack size by a few bytes.</p>
  
  <p>This code will fail on the 4,045th iteration:</p>
  
  <pre><code>count = 0
  loop do
    count += 1
    puts count
    varlist = String.new
    count.times do |i|
      varlist += "a#{i} = 1\n"
    end
    s = "fiber = Fiber.new do \n #{varlist} \n end \n fiber.resume"
    eval(s)
  end
  </code></pre>