如何限制Drupal查询中的内存分配?

I have a Drupal forum site that has large data in it. For example one forum category has 14,000 threads and has 100,000 comments. Even in my local testing site, it's very laggy. Then when I uploaded it to a live site, it gives this error:

Fatal error: Allowed memory size of 52428800 bytes exhausted (tried to allocate 40961 bytes) in /home/fmotors/public_html/development/includes/theme.inc on line 1494

So it has something to do with increasing the memory limit, or to not query all the threads at once. But I don't know how to do either of them. Here's the code which flagged the error above:

function theme_render_template($template_file, $variables) {
  extract($variables, EXTR_SKIP);               // Extract the variables to a local namespace
  ob_start();                                   // Start output buffering
  include DRUPAL_ROOT . '/' . $template_file;   // Include the template file
  return ob_get_clean();                        // End buffering and return its contents
}

The call to ob_start() is on line 1494. By the way, I'm using the advance forum module of Drupal.

in your configuraion or index file set

ini_set('memory_limit', 0);