Ios 你知道为什么一个对象不能在objective-c ARC中释放吗
我试图理解为什么一个对象没有在我的代码中释放,以及如何修复这个问题。我已经为所有类和一个外部库(3.3.0)启用了ARC I在下面的代码中,属性del2未被解除分配(不调用IndoorsTestDelegate的dealloc方法)。del2属性在registerLocationListener:message中传递给室内实例,并在视图控制器中解除锁定期间从中删除。当视图控制器在导航控制器堆栈中被推回时,调用视图控制器的dealloc方法。也会调用IndoorTestDelegate中的del1 dealloc方法,但不会调用del2 dealloc方法。我的问题是为什么不调用del2 dealloc方法,以及如何解决这个问题。我没有来自外部图书馆的资料 这是视图控制器代码:Ios 你知道为什么一个对象不能在objective-c ARC中释放吗,ios,objective-c,memory-management,automatic-ref-counting,Ios,Objective C,Memory Management,Automatic Ref Counting,我试图理解为什么一个对象没有在我的代码中释放,以及如何修复这个问题。我已经为所有类和一个外部库(3.3.0)启用了ARC I在下面的代码中,属性del2未被解除分配(不调用IndoorsTestDelegate的dealloc方法)。del2属性在registerLocationListener:message中传递给室内实例,并在视图控制器中解除锁定期间从中删除。当视图控制器在导航控制器堆栈中被推回时,调用视图控制器的dealloc方法。也会调用IndoorTestDelegate中的del1
#import "IndoorsTestVC.h"
#import "IndoorsTestDelegate.h"
#import <Indoors/Indoors.h>
#import <IndoorsSurface/ISIndoorsSurfaceViewController.h>
@interface IndoorsTestVC ()
@property (strong, nonatomic) IndoorsTestDelegate *del1;
@property (strong, nonatomic) IndoorsTestDelegate *del2;
@end
@implementation IndoorsTestVC
- (void)viewDidLoad
{
[super viewDidLoad];
self.del1 = [[IndoorsTestDelegate alloc]
initWithController:self
andName:@"Del1"];
self.del2 = [[IndoorsTestDelegate alloc]
initWithController:self
andName:@"Del2"];
__unused Indoors *indoors = [[Indoors alloc]
initWithLicenseKey:API_KEY
andServiceDelegate:self.del1];
[[Indoors instance] enableEvaluationMode:NO];
[[Indoors instance] setLogLevel:IDSLogLevelWarning];
[[Indoors instance] registerLocationListener:self.del2];
ISIndoorsSurfaceViewController *surfaceVC = [[ISIndoorsSurfaceViewController alloc] init];
surfaceVC.delegate = self.del1;
// add surfaceVC as a child view controller
[self addChildViewController:surfaceVC];
[self addSubview:surfaceVC.view
withEqualSizeLikeParent:self.view];
[surfaceVC didMoveToParentViewController:self];
// load building
[surfaceVC loadBuildingWithBuildingId:1234];
}
- (void)dealloc {
[[Indoors instance] removeLocationListener:self.del2];
NSLog(@"Dealloc test controller %@", _title);
}
-instance
(室内
)的代码是什么?什么是[[室内实例]registerLocationListener:self.del2];这个类来自外部库,我没有源代码。从文档中可以看出,类方法+实例检索单个对象。室内单例对象使用initWithLicenseKey:和ServiceDelegate:消息初始化。
#import <Foundation/Foundation.h>
#import <Indoors/Indoors.h>
#import <IndoorsSurface/ISIndoorsSurfaceViewController.h>
@interface IndoorsTestDelegate : NSObject <IndoorsServiceDelegate, ISIndoorsSurfaceViewControllerDelegate, IndoorsLocationListener>
@property (weak, nonatomic) UIViewController *controller;
@property (strong, nonatomic) NSString *name;
- (instancetype)initWithController:(UIViewController *) controller
andName:(NSString *)name;
@end
#import "IndoorsTestDelegate.h"
@implementation IndoorsTestDelegate
- (instancetype)initWithController:(UIViewController *)controller
andName:(NSString *)name
{
self = [super init];
if (self) {
_controller = controller;
_name = name;
}
return self;
}
- (void)dealloc {
// This method is called for del1 property
// but for del2 not. Why?
NSLog(@"Dealloc %@", _name);
}
// The protocols methods are empty in testing delegate
#pragma mark IndoorsLocationListener
- (void)zonesEntered:(NSArray *)zones {}
- (void)positionUpdated:(IDSCoordinate *)userPosition {}
- (void)contextUpdated:(IDSContext *)context {}
- (void)changedFloor:(int)floorLevel withName:(NSString *)name {}
- (void)weakSignal {}
- (void)orientationUpdated:(float)orientation {}
#pragma mark ISIndoorsSurfaceViewControllerDelegate
- (void)indoorsSurfaceViewController:(ISIndoorsSurfaceViewController *)indoorsSurfaceViewController isLoadingBuildingWithBuildingId:(NSUInteger)buildingId progress:(NSUInteger)progress {}
- (void)indoorsSurfaceViewController:(ISIndoorsSurfaceViewController *)indoorsSurfaceViewController didFinishLoadingBuilding:(IDSBuilding *)building {}
- (void)indoorsSurfaceViewController:(ISIndoorsSurfaceViewController *)indoorsSurfaceViewController didFailLoadingBuildingWithBuildingId:(NSUInteger)buildingId error:(NSError *)error {}
#pragma mark - IndoorsSurfaceServiceDelegate
- (void)onError:(IndoorsError *)indoorsError {}
- (void)bluetoothStateDidChange:(IDSBluetoothState)bluetoothState {}
- (void)locationAuthorizationStatusDidChange:(IDSLocationAuthorizationStatus)status {}
- (void)connected {}
@end