title: iOS loading a view from nib creates memory leaks?
body: <p>I am trying to load view that contains a map view and 2 buttons, from inside a separate NOB file.</p>
  
  <p>EDIT: I should have mentioned that I must not subclass a UIViewController, because I don't want the view to be presented the standard way (as a modal for example). I want it to use only a quarter of the screen, be transparent, and be presented like a popup view. Therefore, UIVIewController is NOT advisable for a view that won't take up the entire screen or at least won't be presented as a standard modal view controller or a controller of a UINavigationController hierarchy.</p>
  
  <p>Not wanting to use a UIViewController subclass (Apple says to not do that), I decided to build a ContainerObject, descendant of NSObject, that will handle the connections and deallocations.</p>
  
  <p>Inside the container object I only have 1 IBOutlet: (the view). I load the nib this way inside the init function:</p>
  
  <pre><code>- (id)init {
  self = [super init];
  if (self) {
      [[NSBundle mainBundle] loadNibNamed:"myNib" owner:self options:nil];
  }
  return self;
  </code></pre>
  
  <p>}</p>
  
  <p>Inside the NIB there is a view, that has a MapView inside it, and two buttons. As the file's owner I have set the class of my Container object, and the I have connected the "view" outlet to the outlet in the file's owner. The nib load fine, and I am able to load it and add its view to my subview.</p>
  
  <pre><code>self.currentLocationMapView = [[[CurrentLocationViewContainer alloc] init] autorelease];
  self.currentLocationMapView.delegate = self;
  [self.view addSubview:self.currentLocationMapView.view];
  </code></pre>
  
  <p>The problem lies in the deallocation, because while the container object is successfully deallocated, the view is NOT deallocated inside it:</p>
  
  <pre><code>    [self.currentLocationMapView.view removeFromSuperview];
  self.currentLocationMapView = nil;
  </code></pre>
  
  <p>The dealloc message of my custom view, which lies in the container object is never called. I must explicitly call [self.currentLocationMapView.view release] in order to have it deallocated when I want it to.</p>
  
  <p>Note that "self.currentLocationMapView.view" is the container object in my view controller. The container object holds the custom view, which in turn holds the map view and the 2 buttons.</p>