Skip to content

Commit

Permalink
Fix strong ref cycle: Rest.push and Rest.push.admin <-> Rest. (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcard authored Mar 6, 2020
1 parent 96acc8f commit f0e4018
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Source/ARTPush.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ - (void)deactivate {
NSString *const ARTDeviceTokenKey = @"ARTDeviceToken";

@implementation ARTPushInternal {
ARTRestInternal *_rest;
__weak ARTRestInternal *_rest; // weak because rest owns self
ARTLog *_logger;
ARTPushActivationStateMachine *_activationMachine;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/ARTPushAdmin.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ - (ARTPushChannelSubscriptions *)channelSubscriptions {
@end

@implementation ARTPushAdminInternal {
ARTRestInternal *_rest;
__weak ARTRestInternal *_rest; // weak because rest owns self
ARTLog *_logger;
dispatch_queue_t _userQueue;
dispatch_queue_t _queue;
Expand Down
3 changes: 3 additions & 0 deletions Spec/ObjectLifetimes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class ObjectLifetimes: QuickSpec {
var realtime: ARTRealtime? = ARTRealtime(options: options)
weak var internalRealtime: ARTRealtimeInternal? = realtime!.internal
weak var internalConn: ARTConnectionInternal? = realtime!.connection.internal
weak var internalRest: ARTRestInternal? = realtime!.internal.rest

waitUntil(timeout: testTimeout) { done in
options.internalDispatchQueue.async {
realtime = nil // Schedule deallocation for later in this queue
expect(internalConn).toNot(beNil()) // Deallocation still hasn't happened.
expect(internalRealtime).toNot(beNil())
expect(internalRest).toNot(beNil())
done()
}
}
Expand All @@ -37,6 +39,7 @@ class ObjectLifetimes: QuickSpec {
options.internalDispatchQueue.async {
expect(internalConn).to(beNil())
expect(internalRealtime).to(beNil())
expect(internalRest).to(beNil())
done()
}
}
Expand Down

0 comments on commit f0e4018

Please sign in to comment.