Question: Here's a common practice I see often (including from a very popular iPhone developer book)

In the .h file:

```
@interface SomeViewController : UIViewController
{
  UIImageView *imgView;
}

```

Somewhere in the .m file:

```
imgView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen]
applicationFrame]];
[imgView setImage:[UIImage imageNamed:@"someimage.png"]];
[self addSubview:imgView];
[imgView release];

```

And later, we see this...

```
- (void) dealloc
{
  [imgView release];
  [super dealloc];

} 

```

Since imgView has a matching alloc and release, is the release of imgView in dealloc necessary? 

Where is the imgView retained by the addSubview call accounted for?

Answer: 
Release in init is incorrect. 

You mentioned "common practice" and an un-named book. I suggest looking at the canonical examples from Apple: ViewTransitions is a good example for this case (and 2 views to boot ;) 

<http://developer.apple.com/iphone/library/samplecode/ViewTransitions/index.html>
Yes, that code has problems. It releases the imgView too early which could potentially cause crashes in rare circumstances stores an object in an instance variable without retaining it, and it's just generally going about memory management the wrong way.

One correct way to do this would be:

```
@interface SomeViewController : UIViewController
{
    UIImageView *imgView;
}
@property (nonatomic, retain) UIImageView *imgView;

```

And in the implementation;

```
@synthesize imgView;

```

Somewhere in the module:

```
//Create a new image view object and store it in a local variable (retain count 1)
UIImageView *newImgView = [[UIImageView alloc] initWithFrame:self.view.bounds];
newImgView.image = [UIImage imageNamed:@"someimage.png"];

//Use our property to store our new image view as an instance variable,
//if an old value of imgView exists, it will be released by generated method,
//and our newImgView gets retained (retain count 2)
self.imgView = newImgView;

//Release local variable, since the new UIImageView is safely stored in the
//imgView instance variable. (retain count 1)
[newImgView release];

//Add the new imgView to main view, it's retain count will be incremented,
//and the UIImageView will remain in memory until it is released by both the
//main view and this controller. (retain count 2)
[self.view addSubview:self.imgView];

```

And the dealloc remains the same:

```
- (void) dealloc
{
    [imgView release];
    [super dealloc];
}

```