Newbie question - failed to allocate memory

Hi,

I am pretty new in Ruby and Rails programming. I am trying to simply
output data of a really large table with many columns (around 30
columns) in an XML document using erb. I am able to loop through all the
records and output 2 columns. But when I add the following code to
output all the fields of every record the memory usage goes up a lot and
I get a failed to allocate memory error. Any idea why? Should I flush
the buffer? Should I disable the cache? Please help.

<% @records.each do |a| -%>
  <% RecordClass.columns_hash.each do |key,value| -%>
    <SimpleData name="<%= key -%>"><%= a[key] -%></SimpleData>
  <% end -%>
<% end %>

Thanks in advance.