内存泄漏vs僵尸-iPhone

内存泄漏vs僵尸-iPhone,iphone,xcode,memory-leaks,zombie-process,Iphone,Xcode,Memory Leaks,Zombie Process,我的iPhone应用程序要么因僵尸而崩溃,要么内存泄漏。。我已经将其压缩到3行代码,并且可以通过注释/取消注释代码可靠地实现这两件事中的一件。错误发生在结果列表tableView和包含地图和一些标签的详细信息页面之间的导航时,内存泄漏发生在我第一次从地图导航回结果列表时,僵尸发生在可能5/6次导航到不同结果并返回后 #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #define METERS_PER_MILE 1609

我的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];

}

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

我向您推荐:

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

[super dealloc];
}

你把钥匙放在里面了吗?因为IBOutlets是指向xib中对象的链接,所以不需要保留它们。通常是分配的,或者在ARC代码uuu不安全u未保存或较弱的情况下。我尝试将属性更改为非原子,分配,然后不取消分配,或者在dealloc中将它们设置为零,但仍然会得到僵尸。你一直说你有僵尸-这通常会给你更多信息,例如,哪个对象正在发送消息。找到了问题-有趣的是,是我的地图注释的代码导致了崩溃。不管什么原因,我都不喜欢[标题发布]。。用精简版本的代码替换了代码-所有内存泄漏、僵尸和其他讨厌的东西都消失了!该实现泄露了标题和副标题。我认为您的程序在这个类中除了内存管理之外还有其他问题。其他一些代码正在使用UILabel对象?或者它是我用来设置标签值的对象吗?它来自NSDictionary,最初是从JSON请求检索的。它必须是对UILabel本身的某种引用。您是否从另一个类引用UILabel中的值?