title: releasing objects?
body: <p>I'm really new to iPhone programming.</p>
  
  <p>This app is a simple quiz. FirstAppDelegate.m creates an instance of QuizViewController and adds its view to the window.</p>
  
  <pre><code>#import "FirstAppDelegate.h"
  #import "ResultViewController.h"
  #import "QuizViewController.h"
  
  @implementation FirstAppDelegate
  
  @synthesize window;
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions (NSDictionary *)launchOptions {
      UIViewController *vc = [[QuizViewController alloc] init];
      [window addSubview:[vc view]];
      [window makeKeyAndVisible];
      [vc release];
  
      return YES;
  }
  
  - (void)dealloc {
      [window release];
      [super dealloc];
  }
  
  @end
  </code></pre>
  
  <p>I thought I could release vc like I do hear since window will retain it (?) but it generated an error :</p>
  
  <pre><code>2011-06-28 23:06:34.190 First[14289:207] -[__NSCFType foo:]: unrecognized selector sent to instance 0x4e1fc90
  2011-06-28 23:06:34.193 First[14289:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType foo:]: unrecognized selector sent to instance 0x4e1fc90'
  </code></pre>
  
  <p>...so I commented it and now it works fine. But where should I release vc? Here's QuizViewController.h:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface QuizViewController : UIViewController {
      IBOutlet UILabel *questionLabel;
      IBOutlet UIButton *button1;
      IBOutlet UIButton *button2;
      IBOutlet UIButton *button3;
  
      int currentQuestionIndex;
      int corrects;
      NSMutableArray *questions;
      NSMutableArray *answers;
      NSMutableArray *correctAnswers;
  }
  
  - (IBAction)foo:(id)sender;
  
  @end
  </code></pre>
  
  <p>...and QuizViewController.m:</p>
  
  <pre><code>#import "QuizViewController.h"
  
  @implementation QuizViewController
  
  - (id)init {
      NSLog(@"QuizViewController init");
      [super initWithNibName:@"QuizViewController" bundle:nil];
  
      questions = [[NSMutableArray alloc] init];
      answers = [[NSMutableArray alloc] init];
      correctAnswers = [[NSMutableArray alloc] init];
  
      [questions addObject:@"Vad betyder det engelska ordet \"though\"?"];
      [answers addObject:@"Tuff"];
      [answers addObject:@"Dock"];
      [answers addObject:@"Tanke"];
      [correctAnswers addObject:@"Dock"];
  
      [questions addObject:@"Vad hette frontpersonen i Popbandet Queen?"];
      [answers addObject:@"Pierre Bouviere"];
      [answers addObject:@"Freddie Mercury"];
      [answers addObject:@"Stevie Wonder"];
      [correctAnswers addObject:@"Freddie Mercury"];
  
      return self;
  }
  
  
  - (IBAction)foo:(id)sender {
      NSLog(@"foo");
  }
  
  - (void)loadView {
      NSLog(@"QuizViewController loadView");
      [questionLabel setText:[questions objectAtIndex:currentQuestionIndex]];
      [button1 setTitle:[answers objectAtIndex:currentQuestionIndex] forState:UIControlStateNormal];
      [button2 setTitle:[answers objectAtIndex:currentQuestionIndex + 1] forState:UIControlStateNormal];
      [button3 setTitle:[answers objectAtIndex:currentQuestionIndex + 2] forState:UIControlStateNormal];
  
      [super loadView];
  }
  
  - (void)viewDidLoad {
      NSLog(@"QuizViewController viewDidLoad");
      [super viewDidLoad];
  }
  
  - (void)didReceiveMemoryWarning {
      [super didReceiveMemoryWarning];
  }
  
  - (void)viewDidUnload {
      [super viewDidUnload];
  }
  
  - (void)dealloc {
      [super dealloc];
  }
  
  @end
  </code></pre>