Skip to content

Commit e806ca0

Browse files
Avoid RMQConnection leaks by adopting weak refs, take 2 (on behalf of @BarryDuggan)
for some important dependencies of allocated channels and RMQConnection itself. In this client, RMQConnection auto-allocates a channel for the purpose of special "channel zero" (system communication in the protocol) purposes, and that leads to a loop of strong references that prevent RMQConnection instances from being released. Contributed by @BarryDuggan in #194.
1 parent dcae3c7 commit e806ca0

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
iOS_VERSION := 14.4
1+
iOS_VERSION := 15.4
22

33
SCHEME := "RMQClient"
44

@@ -16,7 +16,7 @@ tests_iOS: test_dependencies
1616
xcodebuild test \
1717
-project RMQClient.xcodeproj \
1818
-scheme "${SCHEME}" \
19-
-destination 'platform=iOS Simulator,name=iPhone 12,OS=$(iOS_VERSION)' | \
19+
-destination 'platform=iOS Simulator,name=iPhone 13,OS=$(iOS_VERSION)' | \
2020
xcpretty
2121

2222
tests_MacOS: test_dependencies

RMQClient/RMQAllocatedChannel.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
@interface RMQAllocatedChannel ()
5050
@property (nonatomic, copy, readwrite) NSNumber *channelNumber;
5151
@property (nonatomic, readwrite) NSNumber *contentBodySize;
52-
@property (nonatomic, readwrite) id <RMQDispatcher> dispatcher;
5352
@property (nonatomic, readwrite) NSMutableDictionary *consumers;
5453
@property (nonatomic, readwrite) NSMutableDictionary *exchanges;
5554
@property (nonatomic, readwrite) NSMutableDictionary *exchangeBindings;
@@ -60,7 +59,8 @@ @interface RMQAllocatedChannel ()
6059
@property (nonatomic, readwrite) NSNumber *prefetchCountPerChannel;
6160
@property (nonatomic, readwrite) id<RMQConnectionDelegate> delegate;
6261
@property (nonatomic, readwrite) id<RMQNameGenerator> nameGenerator;
63-
@property (nonatomic, readwrite) id<RMQChannelAllocator> allocator;
62+
@property (nonatomic, weak, readwrite) id<RMQChannelAllocator> allocator;
63+
@property (nonatomic, weak, readwrite) id <RMQDispatcher> dispatcher;
6464
@end
6565

6666
@implementation RMQAllocatedChannel

RMQClient/RMQChannel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ typedef void (^RMQChannelCompletionHandler)(void);
215215
options:(RMQBasicConsumeOptions)options
216216
arguments:(RMQTable * _Nonnull)arguments
217217
handler:(RMQConsumerDeliveryHandler _Nonnull)handler;
218-
218+
219219
/// @brief Internal method used by a consumer object
220220
- (nonnull NSString *)generateConsumerTag;
221221

RMQClient/RMQConnection.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@
6161
#import <RMQProcessInfoNameGenerator.h>
6262

6363
@interface RMQConnection ()
64-
@property (strong, nonatomic, readwrite) id <RMQTransport> transport;
64+
@property ( nonatomic, readwrite) id <RMQTransport> transport;
6565
@property (nonatomic, readwrite) RMQReader *reader;
66-
@property (nonatomic, readwrite) id <RMQChannelAllocator> channelAllocator;
67-
@property (nonatomic, readwrite) id <RMQFrameHandler> frameHandler;
68-
@property (nonatomic, readwrite) id<RMQLocalSerialQueue> commandQueue;
69-
@property (nonatomic, readwrite) id<RMQWaiterFactory> waiterFactory;
70-
@property (nonatomic, readwrite) id<RMQHeartbeatSender> heartbeatSender;
7166
@property (nonatomic, weak, readwrite) id<RMQConnectionDelegate> delegate;
67+
@property (nonatomic, weak, readwrite) id <RMQChannelAllocator> channelAllocator;
68+
@property (nonatomic, weak, readwrite) id <RMQFrameHandler> frameHandler;
69+
@property (nonatomic, readwrite) id<RMQHeartbeatSender> heartbeatSender;
7270
@property (nonatomic, readwrite) id <RMQChannel> channelZero;
7371
@property (nonatomic, readwrite) RMQConnectionConfig *config;
72+
@property (nonatomic, readwrite) id<RMQLocalSerialQueue> commandQueue;
73+
@property (nonatomic, readwrite) id<RMQWaiterFactory> waiterFactory;
7474
@property (nonatomic, readwrite) NSMutableDictionary *userChannels;
7575
@property (nonatomic, readwrite) NSNumber *frameMax;
7676
@property (nonatomic, readwrite) BOOL handshakeComplete;

0 commit comments

Comments
 (0)