about customViewForGraphic method

512
3
02-12-2012 09:27 PM
XiaoJing
New Contributor
I am trying to custom a callout,here is my code:

- (UIView*) customViewForGraphic:   (AGSGraphic *)  graphic
      screenPoint:  (CGPoint)  screen
      mapPoint:  (AGSPoint *)  mapPoint{
NSMutableDictionary *graphicAttr = [graphic attributes];

GraphicDetailViewController *gdv = [[GraphicDetailViewController alloc] initWithAttr:graphicAttr];
gdv.tableView.frame = CGRectMake(screen.x, screen.y, 300, 200);
gdv.tableView.delegate = gdv;
return gdv.tableView;
}

when I compile and analyze,there is a object leak warning:"Object leaked: object allocated and stored into 'gdv' is not referenced later in this execution path and has a retain count of +1".so I use "autorelease" for gdv object,but when i flip the table in callout,the program crashed.the error is :"-[GraphicDetailViewController tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x102d8f00"

how can i resolve this?thanks
0 Kudos
3 Replies
PaulLohr
Occasional Contributor III
Try releasing gdv after it is returned to the method header? Not sure if this will work. Or maybe in the dealloc method?

[gdv release];
0 Kudos
Nicholas-Furness
Esri Regular Contributor

- (UIView*) customViewForGraphic:   (AGSGraphic *)  graphic
      screenPoint:  (CGPoint)  screen
      mapPoint:  (AGSPoint *)  mapPoint{
NSMutableDictionary *graphicAttr = [graphic attributes];

GraphicDetailViewController *gdv = [[GraphicDetailViewController alloc] initWithAttr:graphicAttr];
gdv.tableView.frame = CGRectMake(screen.x, screen.y, 300, 200);
gdv.tableView.delegate = gdv;
return gdv.tableView;
}


There is at least one problem and possibly two with your code, depending on the implementation of GraphicDetailViewController.


  1. You are referencing the GDV as the delegate of the tableView object (so you will add a reference count).

  2. If the GraphicDataViewController's dealloc method releases the tableView object, then you will have a pointer to an object that was released when the GDV was released (this may be what's happening with your "deallocated instance" error).


So, perhaps add a property to your class to store the current GraphicsDataViewController. You would set the property to the GraphicsDataViewController created in customViewForGraphic and release it when the callout showing the GraphicsDataViewController is closed. That way the delegate reference on the returned tableView remains valid for the lifetime of the tableView.
0 Kudos
NimeshJarecha
Esri Regular Contributor
You must create a retain property for the GraphicDetailViewController so it'll be around when you try to view it in the callout.

Regards,
Nimesh
0 Kudos