Skip to content

Commit 4e86d81

Browse files
committed
More retain cycles
1 parent 79c9858 commit 4e86d81

File tree

12 files changed

+29
-25
lines changed

12 files changed

+29
-25
lines changed

MemoryTest/Base.lproj/Main.storyboard

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1818
<subviews>
1919
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="UmE-Cc-1KD">
20-
<rect key="frame" x="162" y="270" width="148" height="31"/>
20+
<rect key="frame" x="20" y="270" width="374" height="31"/>
2121
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2222
<state key="normal" title="Button"/>
23-
<buttonConfiguration key="configuration" style="plain" title="Button"/>
23+
<buttonConfiguration key="configuration" style="plain" title="Reset Connection"/>
2424
<connections>
2525
<action selector="clearConnection" destination="BYZ-38-t0r" eventType="touchUpInside" id="Nbh-hI-wwa"/>
2626
</connections>

MemoryTest/ViewController.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class ViewController: UIViewController {
2525
connection?.close()
2626
connection = nil
2727
print("CLOSED")
28+
connection = RMQConnection()
29+
connection?.start({
30+
print("Connected")
31+
})
2832
}
2933

3034

RMQClient.xcodeproj/xcshareddata/xcschemes/MemoryTest.xcscheme

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,6 @@
5050
ReferencedContainer = "container:RMQClient.xcodeproj">
5151
</BuildableReference>
5252
</BuildableProductRunnable>
53-
<AdditionalOptions>
54-
<AdditionalOption
55-
key = "MallocStackLogging"
56-
value = ""
57-
isEnabled = "YES">
58-
</AdditionalOption>
59-
<AdditionalOption
60-
key = "PrefersMallocStackLoggingLite"
61-
value = ""
62-
isEnabled = "YES">
63-
</AdditionalOption>
64-
<AdditionalOption
65-
key = "MallocScribble"
66-
value = ""
67-
isEnabled = "YES">
68-
</AdditionalOption>
69-
</AdditionalOptions>
7053
</LaunchAction>
7154
<ProfileAction
7255
buildConfiguration = "Release"

RMQClient/RMQChannelAllocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#import "RMQSender.h"
4646

4747
@protocol RMQChannelAllocator <NSObject>
48-
@property (nonatomic, readwrite) id<RMQSender> sender;
48+
@property (nonatomic,weak, readwrite) id<RMQSender> sender;
4949
- (id<RMQChannel>)allocate;
5050
- (void)releaseChannelNumber:(NSNumber *)channelNumber;
5151
- (NSArray<id<RMQChannel>> *)allocatedUserChannels;

RMQClient/RMQConnection.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ - (NSArray *)closeOperationsWithoutBlock {
706706
^{[self.heartbeatSender stop];},
707707
^{
708708
self.transport.delegate = nil;
709+
[self.transport cleanup];
709710
[self.transport close];
710711
},
711712
^{
@@ -725,6 +726,7 @@ - (NSArray *)closeOperations {
725726
^{[self.heartbeatSender stop];},
726727
^{
727728
self.transport.delegate = nil;
729+
[self.transport cleanup];
728730
[self.transport close];
729731
},
730732
^{

RMQClient/RMQReader.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,18 @@ - (void)handleMethodFrame:(RMQFrame *)frame {
104104
}
105105

106106
- (void)readBodiesForIncompleteFrameset:(RMQFrameset *)contentFrameset {
107+
__weak id this = self;
107108
[self.transport readFrame:^(NSData * _Nonnull data) {
108109
RMQFrame *frame = [self frameWithData:data];
109-
110+
__strong typeof(self) strongThis = this;
110111
if ([frame.payload isKindOfClass:[RMQContentBody class]]) {
111-
[self frameset:contentFrameset
112+
[this frameset:contentFrameset
112113
addBodyFrame:frame];
113114
} else {
114-
[self.frameHandler handleFrameset:contentFrameset];
115+
[strongThis.frameHandler handleFrameset:contentFrameset];
115116
RMQFrameset *nonContentFrameset = [[RMQFrameset alloc] initWithChannelNumber:contentFrameset.channelNumber
116117
method:(id <RMQMethod>)frame.payload];
117-
[self.frameHandler handleFrameset:nonContentFrameset];
118+
[strongThis.frameHandler handleFrameset:nonContentFrameset];
118119
}
119120
}];
120121
}

RMQClient/RMQSuspendResumeDispatcher.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
@interface RMQSuspendResumeDispatcher ()
4848
@property (nonatomic, readwrite) id<RMQChannel> channel;
49-
@property (nonatomic, readwrite) id<RMQSender> sender;
49+
@property (nonatomic,weak, readwrite) id<RMQSender> sender;
5050
@property (nonatomic, readwrite) RMQFramesetValidator *validator;
5151
@property (nonatomic, readwrite) id<RMQLocalSerialQueue> commandQueue;
5252
@property (nonatomic, readwrite) id<RMQLocalSerialQueue> enablementQueue;

RMQClient/RMQSynchronizedMutableDictionary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@
4747
- (nullable id)objectForKeyedSubscript:(nonnull id)key;
4848
- (void)setObject:(nonnull id)obj forKeyedSubscript:(nonnull id)key;
4949
- (void)removeObjectForKey:(nonnull id)key;
50+
- (void)removeAllObjects;
5051
@end

RMQClient/RMQSynchronizedMutableDictionary.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,11 @@ - (void)removeObjectForKey:(id)key {
7979
self.count--;
8080
}
8181
}
82+
- (void)removeAllObjects {
83+
@synchronized (self.lock) {
84+
[self.backingDictionary removeAllObjects];
85+
self.count = 0;
86+
}
87+
}
8288

8389
@end

RMQClient/RMQTCPSocketTransport.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ - (void)invokeZeroArityCallback:(long)tag {
229229
foundCallback();
230230
}
231231
}
232+
- (void)cleanup {
233+
[self.callbacks removeAllObjects];
234+
}
232235

233236
- (BOOL)tlsUpgradeWithError:(NSError **)error {
234237
NSArray *certificates = [self.tlsOptions certificatesWithError:error];

0 commit comments

Comments
 (0)