2012-01-31 106 views
1

我的iPhone应用程序由于僵尸或内存泄漏而崩溃..我已将其缩小到3行代码,并可靠地通过注释获得两件事情之一/取消注释代码。在导航结果列表(tableView)和包含地图和一些标签的详细信息页面之间导航时会出现错误,当我从导图第一次导航回到结果列表时,内存泄漏发生,僵尸发生在5/6次导航到不同的结果并返回。内存泄漏vs Zombie - iPhone

#import <UIKit/UIKit.h> 
#import <MapKit/MapKit.h> 

#define METERS_PER_MILE 1609.344 

@interface ResDetailsPageVC : UIViewController <MKMapViewDelegate, UIAlertViewDelegate> { 

UISegmentedControl *mapTypeSwitcher; 
MKMapView *mapView;  

UILabel *nameLabel; 
UIButton *addressLabel; 
UILabel *telephoneLabel; 

NSString *address; 

} 

@property (nonatomic, retain) IBOutlet UISegmentedControl *mapTypeSwitcher; 
@property (nonatomic, retain) IBOutlet MKMapView *mapView; 

@property (nonatomic, retain) IBOutlet UILabel *nameLabel; 
@property (nonatomic, retain) IBOutlet UIButton *addressLabel; 
@property (nonatomic, retain) IBOutlet UILabel *telephoneLabel; 


- (IBAction)segmentedControlIndexChanged; 
- (IBAction)callButtonClick; 
- (IBAction)addressClick; 

- (void) callNumber; 

@end 






@synthesize mapView; 
@synthesize mapTypeSwitcher; 

@synthesize nameLabel, addressLabel, telephoneLabel; 

- (void)dealloc { 

// if these lines are commented out - memory leak 
// if not - zombie?! 
/*self.telephoneLabel = nil; 
self.addressLabel = nil; 
self.nameLabel = nil;*/ 
self.mapView = nil; 
self.mapTypeSwitcher = nil; 

[super dealloc]; 

} 
+0

你把保留在那里?因为IBOutlets是xib中的对象的链接,所以它们不需要保留。通常它们是“分配”的,或者在ARC代码为“__unsafe_unretained”或“weak”的情况下。 – Abizern 2012-01-31 17:05:16

+0

我试着改变属性(非原子,分配),然后不释放或设置他们为零在dealloc但仍然得到僵尸。 – evilunix 2012-02-01 09:31:48

+0

你一直说你有僵尸 - 通常会给你更多的信息,比如什么对象在发送消息。 – Abizern 2012-02-01 10:20:03

回答

0

某处一些其他代码段使用相同的对象,其地址被存储在这三个性质中的一种,但其他的代码还没有正确地保留该对象。

+0

其他一些代码使用UILabel对象?或者它是我用来设置标签值的对象(这来自NSDictionary,最初从JSON请求中检索) – evilunix 2012-02-01 09:38:22

+0

它必须是某种对UILabel本身的引用。你是否从另一个类中引用了UILabel中的值? – 2012-02-01 12:45:14

0

我推荐给你:

- (void)dealloc { 
[telephoneLabel release]; telephoneLabel = nil; 
[addressLabel release]; addressLabel = nil; 
.... 

[super dealloc]; 
} 
+0

等同于他所拥有的。 – 2012-01-31 19:43:26

+0

我仍然使用这个代码得到僵尸... – evilunix 2012-02-01 09:27:22