From 95635f3915960cfb78c04d1c92cd0c113de215f3 Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Thu, 31 Mar 2022 22:04:21 +0400 Subject: [PATCH] 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. --- RMQClient/RMQAllocatedChannel.m | 4 ++-- RMQClient/RMQChannel.h | 2 +- RMQClient/RMQConnection.m | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/RMQClient/RMQAllocatedChannel.m b/RMQClient/RMQAllocatedChannel.m index cc361a71..9b8cf062 100644 --- a/RMQClient/RMQAllocatedChannel.m +++ b/RMQClient/RMQAllocatedChannel.m @@ -49,7 +49,6 @@ @interface RMQAllocatedChannel () @property (nonatomic, copy, readwrite) NSNumber *channelNumber; @property (nonatomic, readwrite) NSNumber *contentBodySize; -@property (nonatomic, readwrite) id dispatcher; @property (nonatomic, readwrite) NSMutableDictionary *consumers; @property (nonatomic, readwrite) NSMutableDictionary *exchanges; @property (nonatomic, readwrite) NSMutableDictionary *exchangeBindings; @@ -60,7 +59,8 @@ @interface RMQAllocatedChannel () @property (nonatomic, readwrite) NSNumber *prefetchCountPerChannel; @property (nonatomic, readwrite) id delegate; @property (nonatomic, readwrite) id nameGenerator; -@property (nonatomic, readwrite) id allocator; +@property (nonatomic, weak, readwrite) id allocator; +@property (nonatomic, weak, readwrite) id dispatcher; @end @implementation RMQAllocatedChannel diff --git a/RMQClient/RMQChannel.h b/RMQClient/RMQChannel.h index f17cd483..c68da070 100644 --- a/RMQClient/RMQChannel.h +++ b/RMQClient/RMQChannel.h @@ -215,7 +215,7 @@ typedef void (^RMQChannelCompletionHandler)(void); options:(RMQBasicConsumeOptions)options arguments:(RMQTable * _Nonnull)arguments handler:(RMQConsumerDeliveryHandler _Nonnull)handler; - + /// @brief Internal method used by a consumer object - (nonnull NSString *)generateConsumerTag; diff --git a/RMQClient/RMQConnection.m b/RMQClient/RMQConnection.m index c49481dc..d9640f9d 100644 --- a/RMQClient/RMQConnection.m +++ b/RMQClient/RMQConnection.m @@ -61,16 +61,16 @@ #import "RMQProcessInfoNameGenerator.h" @interface RMQConnection () -@property (strong, nonatomic, readwrite) id transport; +@property ( nonatomic, readwrite) id transport; @property (nonatomic, readwrite) RMQReader *reader; -@property (nonatomic, readwrite) id channelAllocator; -@property (nonatomic, readwrite) id frameHandler; -@property (nonatomic, readwrite) id commandQueue; -@property (nonatomic, readwrite) id waiterFactory; -@property (nonatomic, readwrite) id heartbeatSender; @property (nonatomic, weak, readwrite) id delegate; +@property (nonatomic, weak, readwrite) id channelAllocator; +@property (nonatomic, weak, readwrite) id frameHandler; +@property (nonatomic, readwrite) id heartbeatSender; @property (nonatomic, readwrite) id channelZero; @property (nonatomic, readwrite) RMQConnectionConfig *config; +@property (nonatomic, readwrite) id commandQueue; +@property (nonatomic, readwrite) id waiterFactory; @property (nonatomic, readwrite) NSMutableDictionary *userChannels; @property (nonatomic, readwrite) NSNumber *frameMax; @property (nonatomic, readwrite) BOOL handshakeComplete;