RMQConnection leaking memory when recreated #194
Replies: 7 comments 13 replies
-
@BarryDuggan I don't see any evidence of a problem in the client. It does not instantiate or keep references to You are welcome to investigate this and provide evidence and recommendations (or simply submit a PR), this is open source software after all. |
Beta Was this translation helpful? Give feedback.
-
Here is another more contrived example to illustrate that there is nothing in the app holding a reference to the RMQConnection.
|
Beta Was this translation helpful? Give feedback.
-
@michaelklishin Below are the changes I made locally. RMQAllocatedChannel
RMQConnection
My Errors |
Beta Was this translation helpful? Give feedback.
-
@BarryDuggan does this diff look correct to you? I'd be happy to create a PR (with all credit given to you) and run test suites locally with it. diff --git a/RMQClient/RMQAllocatedChannel.m b/RMQClient/RMQAllocatedChannel.m
index eaa4df7..45bdfca 100644
--- a/RMQClient/RMQAllocatedChannel.m
+++ b/RMQClient/RMQAllocatedChannel.m
@@ -49,7 +49,7 @@
@interface RMQAllocatedChannel ()
@property (nonatomic, copy, readwrite) NSNumber *channelNumber;
@property (nonatomic, readwrite) NSNumber *contentBodySize;
-@property (nonatomic, readwrite) id <RMQDispatcher> dispatcher;
+@property (nonatomic, weak, readwrite) id <RMQDispatcher> dispatcher;
@property (nonatomic, readwrite) NSMutableDictionary *consumers;
@property (nonatomic, readwrite) NSMutableDictionary *exchanges;
@property (nonatomic, readwrite) NSMutableDictionary *exchangeBindings;
@@ -58,9 +58,9 @@
@property (nonatomic, readwrite) id<RMQConfirmations> confirmations;
@property (nonatomic, readwrite) NSNumber *prefetchCountPerConsumer;
@property (nonatomic, readwrite) NSNumber *prefetchCountPerChannel;
-@property (nonatomic, readwrite) id<RMQConnectionDelegate> delegate;
+@property (nonatomic, weak, readwrite) id<RMQConnectionDelegate> delegate;
@property (nonatomic, readwrite) id<RMQNameGenerator> nameGenerator;
-@property (nonatomic, readwrite) id<RMQChannelAllocator> allocator;
+@property (nonatomic, weak, readwrite) id<RMQChannelAllocator> allocator;
@end
@implementation RMQAllocatedChannel
diff --git a/RMQClient/RMQConnection.m b/RMQClient/RMQConnection.m
index 2a0aafc..1930c9e 100644
--- a/RMQClient/RMQConnection.m
+++ b/RMQClient/RMQConnection.m
@@ -60,22 +60,19 @@
#import <RMQFrame.h>
#import <RMQProcessInfoNameGenerator.h>
-@interface RMQConnection ()
-@property (strong, nonatomic, readwrite) id <RMQTransport> transport;
-@property (nonatomic, readwrite) RMQReader *reader;
-@property (nonatomic, readwrite) id <RMQChannelAllocator> channelAllocator;
-@property (nonatomic, readwrite) id <RMQFrameHandler> frameHandler;
+@property (weak, nonatomic, readwrite) id <RMQTransport> transport;
+@property (nonatomic, weak, readwrite) RMQReader *reader;
+@property (nonatomic, weak, readwrite) id <RMQChannelAllocator> channelAllocator;
+@property (nonatomic, weak, readwrite) id <RMQFrameHandler> frameHandler;
@property (nonatomic, readwrite) id<RMQLocalSerialQueue> commandQueue;
@property (nonatomic, readwrite) id<RMQWaiterFactory> waiterFactory;
-@property (nonatomic, readwrite) id<RMQHeartbeatSender> heartbeatSender;
-@property (nonatomic, weak, readwrite) id<RMQConnectionDelegate> delegate;
+@property (nonatomic, weak, readwrite) id<RMQHeartbeatSender> heartbeatSender;
@property (nonatomic, readwrite) id <RMQChannel> channelZero;
-@property (nonatomic, readwrite) RMQConnectionConfig *config;
+@property (nonatomic, weak, readwrite) RMQConnectionConfig *config;
@property (nonatomic, readwrite) NSMutableDictionary *userChannels;
@property (nonatomic, readwrite) NSNumber *frameMax;
@property (nonatomic, readwrite) BOOL handshakeComplete;
@property (nonatomic, readwrite) NSNumber *handshakeTimeout;
-@end
__attribute__((constructor))
static void RMQInitConnectionConfigDefaults() { |
Beta Was this translation helpful? Give feedback.
-
Second attempt: #196 |
Beta Was this translation helpful? Give feedback.
-
Third attempt: #197 |
Beta Was this translation helpful? Give feedback.
-
One caveat I'm seeing. By making the heartbeatSender property weak, it isn't retained anywhere and thus is dropped. When start is called on the connection, strongThis.heartbeatSender will be nil. No heartbeats get sent, and the broker will kick the client. |
Beta Was this translation helpful? Give feedback.
-
RMQConnection leaking memory when recreated.
Steps to reproduce
In Xcode Set Live Allocation Logging
Repeat steps 1 - 4 a few times
Select Memory Graph in Xcode to View Memory Warnings
Expected Results
1 instance of RMQConnection Will Exist
Actual Results
Multiple instances of RMQConnection Exist.
Many Memory Leaks reported in Xcode.
Sample Code
Beta Was this translation helpful? Give feedback.
All reactions