首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >内存泄漏vs僵尸- iPhone

内存泄漏vs僵尸- iPhone
EN

Stack Overflow用户
提问于 2012-02-01 00:59:08
回答 2查看 476关注 0票数 1

我的iPhone应用程序要么因为僵尸而崩溃,要么是内存泄漏。我已经将其缩小到3行代码,并且可以通过注释/取消注释代码来可靠地实现这两种情况之一。当在结果列表(tableView)和包含地图和一些标签的详细信息页面之间导航时,会出现错误;当我第一次从地图导航回到结果列表时,会发生内存泄漏;僵尸可能会在导航到不同结果并返回5/6次后发生。

代码语言:javascript
复制
#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];

}
EN

回答 2

Stack Overflow用户

发布于 2012-02-01 01:05:45

在某个地方,另一段代码正在使用同一对象,该对象的地址存储在这三个属性中的一个属性中,但另一段代码没有正确保留该对象。

票数 0
EN

Stack Overflow用户

发布于 2012-02-01 01:06:12

我建议你这样做:

代码语言:javascript
复制
- (void)dealloc {
[telephoneLabel release]; telephoneLabel = nil;
[addressLabel release]; addressLabel = nil;
....

[super dealloc];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9083626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档