Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Read the <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html" rel="nofollow noreferrer">memory management rules</a>. 9 simple paragraphs that explain everything you need to know.</p> <p>Because geekName does not begins with “alloc” or “new” or contains “copy”, it should be returning a string you do not “own”. As such, you do not need to (and indeed, must not) release it, and you also must not store a reference to it. You may return it from the method you are in, in which case your method name also should not begins with “alloc” or “new” or contains “copy”.</p> <p>If you wish to keep it around, you must take ownership of it by calling retain, or because its an NSString, better is copy. This might be automatic if you assign it to a copy/retain property.</p> <p>In the code you have now posted, you have made an error in your setter. Your setter should be taking a copy of the input parameter, something like:</p> <pre><code>- (void)setGeekName:(NSString*)gName { if ( geekName != gName ) { [geekName release]; geekName = [gName copy]; } </code></pre> <p>You then also need a dealloc routines which releases geekName:</p> <pre><code>- (void) dealloc { [geekName release]; [super dealloc]; } </code></pre> <p>Alternatively, you can use Objective C properties. Instead of your interface showing:</p> <pre><code>- (NSString*) geekName; - (void) setGeekName:(NSString*)gName; </code></pre> <p>Use a property:</p> <pre><code>@property (nonatomic, copy) NSString* geekName; </code></pre> <p>And instead of your implementation of the setters and getters, let the system synthesize them for you:</p> <pre><code>@synthesize geekName; </code></pre> <p>You still need the dealloc method to free geekName.</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