Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you define <code>@property</code> then generally any time you access the ivar in your class you use the getter/setter whether that be dot notation or standard method call.</p> <p><strong>Dot notation</strong></p> <pre><code>id localyMyVar = self.myVar; self.myVar = @"A string"; </code></pre> <p><strong>Standard method call</strong></p> <pre><code>id localMyVar = [self myVar]; [self setMyVar:@"A string"]; </code></pre> <p>If you always explicitly use these getters and setters then you pretty much do not need to call release anywhere in your code apart from <code>dealloc</code> or an overridden <code>setMyVar:</code> method. Doing it this way allows memory management to occur in limited places. If you start releasing and retaining yourself then things can be a bit complicated when you first start out.</p> <p><strong>UPDATE</strong></p> <p>@bbum gives you the answer but I think you would benefit from being more consistant in your coding as well. </p> <p>For example before the offending line you are assigning directly to an ivar without using the setter. Be consistant and use the setter/getter that you took the time to synthesize. I would rewrite</p> <pre><code>tools = [[[TransparentToolbar alloc] initWithFrame:CGRectMake(0, 0, 70, 44.01)] autorelease]; tools.barStyle = UIBarStyleBlackOpaque; </code></pre> <p>to </p> <pre><code>TransparentToolbar *tmpTools = [[TransparentToolbar alloc] initWithFrame:CGRectMake(0, 0, 70, 44.01)]; tmpTools.barStyle = UIBarStyleBlackOpaque; self.tools = tmpTools; [tmpTools release]; tmpTools = nil; </code></pre> <p>Your <code>init</code> methods are not really following the guidelines either you should be checking that <code>self</code> is actually set, so it should look something similar to:</p> <pre><code>- (id)init { self = [super init]; if (self) { [self applyTranslucentBackground]; } return self; } </code></pre> <p><strong>UPDATE</strong></p> <p>The memory leak you are seeing here:</p> <pre><code>self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.tools]; </code></pre> <p>is because you look at the docs for <a href="http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UINavigationItem_Class/Reference/UINavigationItem.html" rel="nofollow">UINavigationItem</a> you will see that <code>rightBarButtonItem</code> is declared as <code>retain</code></p> <pre><code>@property(nonatomic, retain) UIBarButtonItem *rightBarButtonItem </code></pre> <p>Therefore the call <code>self.navigationItem.rightBarButtonItem</code> will take a +1 retain on the object you pass in and then you are alloc/initing which is another +1 retain. The <code>UINavigationItem</code> will release it's retain when it is dealloc'd but there will still be your original retain hanging around.</p> <p>The fix:</p> <pre><code>UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.tools]; self.navigationItem.rightBarButtonItem = rightBarButtonItem; [rightBarButtonItem release]; rightBarButtonItem = nil; </code></pre>
 

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