我的iPhone应用程序要么因僵尸而崩溃,要么泄漏内存..我已经将其缩小到3行代码,并且通过注释/取消注释代码可以可靠地获得两件事之一。当结果列表(tableView)和包含地图和几个标签的详细信息页面之间导航时发生错误,内存泄漏发生在我第一次从地图导航回结果列表时,僵尸发生在5或之后6次导航到不同的结果并返回。
#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 :(得分:0)
某处某些代码正在使用相同的对象,其地址存储在这三个属性中的一个中,但是另一段代码没有正确保留该对象。
答案 1 :(得分:0)
我向你推荐这个:
- (void)dealloc {
[telephoneLabel release]; telephoneLabel = nil;
[addressLabel release]; addressLabel = nil;
....
[super dealloc];
}