Cody
Cody

Reputation: 8954

C# OutOfMemoryException

I'm getting an out of memory exception on this loop...however, it never even reaches a second iteration. The date index is 0 when the exception is thrown.

<% int date = 0; %>
   <% while (date < Model.TimePeriod1.Count) { %>
      <tr>
         <% for (int i = 0; i < 7; i++)
            { %>
               <td><%: Model.TimePeriod1[date] %></td>
                  date = date + 1;
                  <% } %>
      </tr>
   <% } %>

Upvotes: 1

Views: 341

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1063864

Your date = date + 1; is html, not code; hence it never changes date, hence it fills the entire memory with the output-buffer for lots and lots and lots of Model.TimePeriod1[0]. Add a bee-sting after the %></td>:

  <tr>
     <% for (int i = 0; i < 7; i++)
        { 
           %><td><%: Model.TimePeriod1[date] %></td><%
           date = date + 1;
        } %>
  </tr>

Upvotes: 5

Related Questions