title: typedef struct in Obj-c
body: <p>I'm seeing a weird behavior and I would need some help with it.</p>
  
  <p>In structure.h I have:</p>
  
  <pre><code>typedef struct {
      NSString *summary;
      NSArray *legs;
      NSString *copyrights;
      struct polylineSruct overview_polyline;
      struct directionBounds bounds;    
  } route;
  
  typedef struct {
      NSArray *routes;
      NSString *status;
  } directions;
  </code></pre>
  
  <p>In structure.m I have:</p>
  
  <pre><code>(directions) a_Function_that_builds_the_struct
  {
      directions direct;
  
      direct.status = @"OK";
  
      NSMutableArray *routes = [NSMutableArray array];
      for(xxx)
      {
          route routeL;
          routeL.summary = @"1";
          routeL.copyrights = @"2";
  
          NSValue *boxedroute = [NSValue valueWithBytes:&amp;routeL objCType:@encode(route)];
          [routes addObject:boxedroute];
      }
  
      direct.routes = routes;
  
      return direct;
  }
  </code></pre>
  
  <p>in list_itemsViewController.h I have:</p>
  
  <pre><code>implementation XXX:YYY{
      directions directionsLoc;
  }
  @property (assign) directions directionsLoc;
  </code></pre>
  
  <p>in list_itemsViewController.h I have:</p>
  
  <pre><code>@synthesize directionsLoc;
  ....
  - (void)viewDidLoad
  {
      ....
      self.directionsLoc = a_Function_that_builds_the_struct;
      ....
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
      return [directionsLoc.routes count];
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      ....
      cell.textLabel.text = directionsLoc.status
      return cell;
  }
  </code></pre>
  
  <p>When I start the application I get the list with all the correct rows, if I scroll a little bit for the tableView:cellForRowAtIndexPath: the property directionsLoc is deallocated.</p>
  
  <p>Does anybody have any idea why I get this problem? Is it because I use typedef and the retention is not kept? If I return in the a_Function_that_builds_the_struct and NSArray of directions when the scrolling happens and tableView:cellForRowAtIndexPath: is executed the array had one element as expected but the status and routes elements of the object are zombies.</p>
  
  <p>Any thought on why this happens?</p>
  
  <p>Thank you.</p>