Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my property a potential leak and how can I fix it?
    text
    copied!<p>I have a <strong>UIScrollView</strong> in my <strong>UIViewController</strong> defined as this in my .h file:</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface TestViewController : UIViewController &lt;UIScrollViewDelegate&gt; @property (nonatomic, retain) UIScrollView * imageScrollView; @end </code></pre> <p>Then in my .m file I have the following:</p> <pre><code>@synthesize imageScrollView = _imageScrollView; </code></pre> <p>I read that this will automatically create the _imageScrollView that I would normally type in the .h file? (UIScrollView * _imageScrollView)</p> <p>I like it, because it removes duplicate code from my .h files. Now in my <strong>loadView</strong> I do the rest:</p> <pre><code>self.imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0 - 20.0 - 49.0)]; [_imageScrollView setDelegate:self]; [_imageScrollView setPagingEnabled:YES]; [_imageScrollView setBounces:NO]; [_imageScrollView setShowsHorizontalScrollIndicator:NO]; [_imageScrollView setShowsVerticalScrollIndicator:NO]; [_imageScrollView setContentSize:CGSizeMake(320.0 * 3.0, 480.0 - 20.0 - 49.0)]; </code></pre> <p>And in the <strong>dealloc</strong> release and nil:</p> <pre><code>- (void)dealloc { [_imageScrollView release], _imageScrollView = nil; [super dealloc]; } </code></pre> <p>Now after a build Xcode is telling me this:</p> <pre><code>Potential leak of an object allocated on line #linenumber </code></pre> <p>This will go away when I change this:</p> <pre><code>self.imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0 - 20.0 - 49.0)]; </code></pre> <p>to this:</p> <pre><code>self.imageScrollView = [[[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0 - 20.0 - 49.0)] autorelease]; </code></pre> <p>Why do I need to autorelease this when I'm release it in dealloc? What am I doing wrong?</p> <p>This memory warning only occurs in Xcode on my iMac with Lion installed, not on my macbook with snow leopard...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload