You are here

function view::destroy in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 6.2 includes/view.inc \view::destroy()
  2. 7.3 includes/view.inc \view::destroy()

Unset references so that a $view object may be properly garbage collected.

File

includes/view.inc, line 1827
view.inc Provides the view object type and associated methods.

Class

view
An object to contain all of the data to generate a view, plus the member functions to build the view query, execute the query and render the output.

Code

function destroy() {
  foreach (array_keys($this->display) as $display_id) {
    if (isset($this->display[$display_id]->handler)) {
      $this->display[$display_id]->handler
        ->destroy();
      unset($this->display[$display_id]->handler);
    }
  }
  foreach (views_object_types() as $type => $info) {
    if (isset($this->{$type})) {
      $handlers =& $this->{$type};
      foreach ($handlers as $id => $item) {
        $handlers[$id]
          ->destroy();
      }
      unset($handlers);
    }
  }
  if (isset($this->style_plugin)) {
    $this->style_plugin
      ->destroy();
    unset($this->style_plugin);
  }

  // Clear these to make sure the view can be processed/used again.
  if (isset($this->display_handler)) {
    unset($this->display_handler);
  }
  if (isset($this->current_display)) {
    unset($this->current_display);
  }
  if (isset($this->query)) {
    unset($this->query);
  }
  $keys = array(
    'current_display',
    'display_handler',
    'build_info',
    'built',
    'executed',
    'attachment_before',
    'attachment_after',
    'field',
    'argument',
    'filter',
    'sort',
    'relationship',
    'header',
    'footer',
    'empty',
    'query',
    'result',
    'inited',
    'style_plugin',
    'plugin_name',
    'exposed_data',
    'exposed_input',
    'many_to_one_tables',
  );
  foreach ($keys as $key) {
    if (isset($this->{$key})) {
      unset($this->{$key});
    }
  }
  $this->built = $this->executed = FALSE;
  $this->build_info = array();
  $this->attachment_before = '';
  $this->attachment_after = '';
}