Any ideas why one object is not deallocated in objective-c ARC

142 views Asked by At

I'm trying to understand why one object is not deallocating in my code and how to fix this. I have ARC enabled for all classes and one external library IndoorsSDK-iOS (3.3.0).

I the following code the property del2 is not deallocated (The dealloc method of the IndoorsTestDelegate is not called). The del2 property is passed to Indoors instance in registerLocationListener: message and is removed from it during dealloc in view controller. The dealloc method of View Controller is called when the View Controller is Pushed back in Navigation Controller stack. The del1 dealloc method from IndoorsTestDelegate also is called but del2 dealloc method is not called. And my question is why del2 dealloc method is not called and how can I fix this. I don't have sources from external library.

This is the View Controller code:

#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);
}

This is the IndoorsTestDelegate.h:

#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

And IndoorsTestDelegate.m:

#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
0

There are 0 answers