我的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];
}发布于 2012-02-01 01:05:45
在某个地方,另一段代码正在使用同一对象,该对象的地址存储在这三个属性中的一个属性中,但另一段代码没有正确保留该对象。
发布于 2012-02-01 01:06:12
我建议你这样做:
- (void)dealloc {
[telephoneLabel release]; telephoneLabel = nil;
[addressLabel release]; addressLabel = nil;
....
[super dealloc];
}https://stackoverflow.com/questions/9083626
复制相似问题