我的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];
}
你把保留在那里?因为IBOutlets是xib中的对象的链接,所以它们不需要保留。通常它们是“分配”的,或者在ARC代码为“__unsafe_unretained”或“weak”的情况下。 – Abizern 2012-01-31 17:05:16
我试着改变属性(非原子,分配),然后不释放或设置他们为零在dealloc但仍然得到僵尸。 – evilunix 2012-02-01 09:31:48
你一直说你有僵尸 - 通常会给你更多的信息,比如什么对象在发送消息。 – Abizern 2012-02-01 10:20:03