Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Never pass ownership around. I.e., in your call to initWithId: you create a string. Make sure it's released in the exact same place. Do not hand the ownership over, burdening another function with the task of releasing what you created (or retained, ...).</p> <p>If you're not calling initWithId: an unusually high number of times per second, do an autorelease. Even better, use a convenience function. Do not let people talk you into "avoiding the autorelease pool". Because a) it's not so easy to avoid and b) you have more important things to worry about.</p> <p>In code:</p> <pre><code>NSString* graphID = [NSString stringWithFormat: @"%s", current_ID]; GraphViewController* graph = [[[GraphViewController alloc] initWithId: graphID] autorelease]; </code></pre> <p>In the constructor, you will simply retain the ID and in the dealloc you will release it again. And please... use (private) @property declarations for this. You can then completely remove the ivar "graphID" from your public interface (if it's private, of course).</p> <pre><code>@interface GraphViewController () @property (copy, nonatomic) NSString* graphID; // copy instead of retain for potentially mutable objects @end </code></pre> <p>Then, in initializer and dealloc, boilerplate stuff like:</p> <pre><code>@synthesize graphID; - (id)initWithId:(NSString*) ID; { self = [super init]; self.graphID = ID; return self; } - (void) dealloc { self.graphID = nil; // controversial, Apple policy is [graphID release]; graphID = nil; [super dealloc]; } </code></pre> <p>Using this style will make you sleep better at night. Delighted users will raise statues in your name.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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