Skip to content

Commit 2c6f8d2

Browse files
committed
Make MXRoomAccountDataUpdater and MXRoomSummaryUpdater map tables weak.
1 parent 55a9408 commit 2c6f8d2

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

MatrixSDK/Data/MXRoom.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ - (MXHTTPOperation*)sendEventOfType:(MXEventTypeString)eventTypeString
546546

547547
MXWeakify(self);
548548
void(^onSuccess)(NSString *) = ^(NSString *eventId) {
549+
MXStrongifyAndReturnIfNil(self);
549550

550551
if (event)
551552
{
@@ -559,7 +560,6 @@ - (MXHTTPOperation*)sendEventOfType:(MXEventTypeString)eventTypeString
559560
// Update stored echo.
560561
// We keep this event here as local echo to handle correctly outgoing messages from multiple devices.
561562
// The echo will be removed when the corresponding event will come through the server sync.
562-
MXStrongifyAndReturnIfNil(self);
563563
[self updateOutgoingMessage:localEventId withOutgoingMessage:event];
564564
}
565565

@@ -568,11 +568,11 @@ - (MXHTTPOperation*)sendEventOfType:(MXEventTypeString)eventTypeString
568568
success(eventId);
569569
}
570570

571-
MXStrongifyAndReturnIfNil(self);
572571
[self handleNextOperationAfter:roomOperation];
573572
};
574573

575574
void(^onFailure)(NSError *) = ^(NSError *error) {
575+
MXStrongifyAndReturnIfNil(self);
576576

577577
if (event)
578578
{
@@ -581,7 +581,6 @@ - (MXHTTPOperation*)sendEventOfType:(MXEventTypeString)eventTypeString
581581
event.sentState = MXEventSentStateFailed;
582582

583583
// Update the stored echo.
584-
MXStrongifyAndReturnIfNil(self);
585584
[self updateOutgoingMessage:event.eventId withOutgoingMessage:event];
586585
}
587586

@@ -590,7 +589,6 @@ - (MXHTTPOperation*)sendEventOfType:(MXEventTypeString)eventTypeString
590589
failure(error);
591590
}
592591

593-
MXStrongifyAndReturnIfNil(self);
594592
[self handleNextOperationAfter:roomOperation];
595593
};
596594

@@ -1039,13 +1037,13 @@ - (MXHTTPOperation*)sendImage:(NSData*)imageData
10391037

10401038
MXWeakify(self);
10411039
void(^onSuccess)(NSString *) = ^(NSString *eventId) {
1040+
MXStrongifyAndReturnIfNil(self);
10421041

10431042
if (success)
10441043
{
10451044
success(eventId);
10461045
}
10471046

1048-
MXStrongifyAndReturnIfNil(self);
10491047
[self handleNextOperationAfter:roomOperation];
10501048
};
10511049

MatrixSDK/Data/MXRoomAccountDataUpdater.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ + (instancetype)roomAccountDataUpdaterForSession:(MXSession *)mxSession
2828

2929
static dispatch_once_t onceToken;
3030
dispatch_once(&onceToken, ^{
31-
updaterPerSession = [[NSMapTable alloc] init];
31+
updaterPerSession = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsWeakMemory
32+
valueOptions:NSPointerFunctionsWeakMemory
33+
capacity:1];
3234
});
3335

3436
MXRoomAccountDataUpdater *updater = [updaterPerSession objectForKey:mxSession];

MatrixSDK/Data/MXRoomSummaryUpdater.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ + (instancetype)roomSummaryUpdaterForSession:(MXSession *)mxSession
4444

4545
static dispatch_once_t onceToken;
4646
dispatch_once(&onceToken, ^{
47-
updaterPerSession = [[NSMapTable alloc] init];
47+
updaterPerSession = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsWeakMemory
48+
valueOptions:NSPointerFunctionsWeakMemory
49+
capacity:1];
4850
});
4951

5052
MXRoomSummaryUpdater *updater = [updaterPerSession objectForKey:mxSession];

MatrixSDK/MXSession.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,12 +1084,16 @@ typedef void (^MXOnBackgroundSyncFail)(NSError *error);
10841084
/**
10851085
Delegate for updating room summaries.
10861086
By default, it is the one returned by [MXRoomSummaryUpdater roomSummaryUpdaterForSession:].
1087+
1088+
This property is strong as the only other reference to the delegate is a weak ref in the updaterPerSession table.
10871089
*/
10881090
@property id<MXRoomSummaryUpdating> roomSummaryUpdateDelegate;
10891091

10901092
/**
10911093
Delegate for updating room account data.
10921094
By default, it is the one returned by [MXRoomAccountDataUpdater roomAccountDataUpdaterForSession:].
1095+
1096+
This property is strong as the only other reference to the delegate is a weak ref in the updaterPerSession table.
10931097
*/
10941098
@property id<MXRoomAccountDataUpdating> roomAccountDataUpdateDelegate;
10951099

changelog.d/5805.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MXRoom: Fix retain cycles, in particular between MXRoomOperation and its block.

0 commit comments

Comments
 (0)