IOSAD-172 Handle the timer IOSAD-172
authorDirk Zimmermann <dz@pep.security>
Fri, 26 Jun 2020 16:54:34 +0200
branchIOSAD-172
changeset 1475cf82c13266ac
parent 1474 a37a548a6b3b
child 1476 388741294076
IOSAD-172 Handle the timer
pEpObjCAdapter/PEPPassphraseCache.m
     1.1 --- a/pEpObjCAdapter/PEPPassphraseCache.m	Fri Jun 26 16:54:34 2020 +0200
     1.2 +++ b/pEpObjCAdapter/PEPPassphraseCache.m	Fri Jun 26 16:54:34 2020 +0200
     1.3 @@ -20,6 +20,7 @@
     1.4  
     1.5  @property (nonatomic) dispatch_queue_t queue;
     1.6  @property (nonatomic) NSMutableArray<PEPPassphraseCacheEntry *> *mutablePassphrases;
     1.7 +@property (nonatomic) NSTimer *checkExpiryTimer;
     1.8  
     1.9  @end
    1.10  
    1.11 @@ -34,10 +35,24 @@
    1.12          _timeout = timeout;
    1.13          _queue = dispatch_queue_create("PEPPassphraseCache Queue", DISPATCH_QUEUE_SERIAL);
    1.14          _mutablePassphrases = [NSMutableArray arrayWithCapacity:s_maxNumberOfPassphrases];
    1.15 +
    1.16 +        // we have a strong reference to the timer, but the timer doesn't have one to us
    1.17 +        typeof(self) __weak weakSelf = self;
    1.18 +        _checkExpiryTimer = [NSTimer
    1.19 +                             scheduledTimerWithTimeInterval:checkExpiryInterval
    1.20 +                             repeats:YES
    1.21 +                             block:^(NSTimer *timer) {
    1.22 +            [weakSelf removeStaleEntries];
    1.23 +        }];
    1.24      }
    1.25      return self;
    1.26  }
    1.27  
    1.28 +- (void)dealloc
    1.29 +{
    1.30 +    [_checkExpiryTimer invalidate];
    1.31 +}
    1.32 +
    1.33  /// Public constructor with default values.
    1.34  - (instancetype)init
    1.35  {