iPhone - self dismissing a viewController
<p>I have a view controller that was presented using</p>

<pre><code>[self presentModalViewController:myVC animated:YES];
</code></pre>

<p>this VC has several declared retained properties (@property) that I have to release on its dealloc. </p>

<p>The variables are declared as</p>

<pre><code>@property (nonatomic,retain) myClass1 *myProperty;
@property (nonatomic,retain) myClass2 *myProperty2;
// etc... and then synthesized on .m
</code></pre>

<p>The problem is that when I dismiss the viewController using </p>

<pre><code>[self dismissModalViewControllerAnimated:YES];  
</code></pre>

<p>it crashes on the dealloc, when releasing the retained properties I have declared, with the error *<em>modifying layer that is being finalized *</em> </p>

<p>Apparently the the viewController is gone at the time its own dealloc runs and then it crashes.</p>

<p>How do I solve that? Thanks in advance.</p>

<h2>edit</h2>

<p>the code that presents the viewController is on the rootViewController and is this:</p>

<pre><code>UIViewController *myVC = [[UIViewController alloc] init];
myVC.delegate = self;

UINavigationController *navigator = [[UINavigationController alloc] initWithRootViewController:myVC];

[self presentModalViewController:navigator animated:YES];
[navigator release];
[myVC release];
</code></pre>

<p>and this is the what the dealloc code on myVC contains</p>

<pre><code>- (void) dealloc {
  [myProperty1 release]; // see this properties at the beginning of this question
  [myProperty1 release]; // if I comment these 2 relesases it stops crashing
  [super dealloc];
}
</code></pre>

<p>myVC is dismissed from inside itself, but that's fine according to the docs. I have also tried to dismiss it from the rootviewController but it continues to crash. The only way to stop crashing is to disable the release lines on the dealloc.</p>
