-
Notifications
You must be signed in to change notification settings - Fork 886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes memory leaks in IoT #1175
Fixes memory leaks in IoT #1175
Conversation
@@ -639,6 +672,12 @@ - (void)openStreams:(id)sender | |||
[defaultRunLoopTimer invalidate]; | |||
|
|||
if (!self.runLoopShouldContinue ) { | |||
|
|||
if (self.connectionAgeTimer != nil ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cbommas, your earlier suggestion to simplify this was correct as this method will be called already on the correct thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// NOTE: This does not work as intended. The reconnection attempt is always done on the reconnect thread | ||
// but the timer needs to be invalidated on the streams thread to ensure memory is released. | ||
// However, as currently implemented a switch to the streams thread here to clean this up is always beaten to the | ||
// invalidation by other events which are are already being processed on the streams thread. | ||
[self.connectionAgeTimer invalidate]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted this doesn't really work but other code avoids a memory leak. Ideally, this would have code to switch threads to clean up correctly but I left this alone for now as by the time a thread switch got control another event had already done the cleanup. I can update PR to have the thread switch if desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this change, rather than doing a thread switch, lets just remove this code, as it is handled in one of the other events.
Can we break this PR up into two separate ones? There are changes to the IOT code and the Core code. The challenge I have with AWSCore code changes is that we had to make the change to not invalidate the session due to crashes ( see #913). We will have to dive deeper on this. For the IOT changes, I will be testing them and prepping for release, pending the test results. |
Similar to earlier PR with another memory leak fixed and target most recent SDK version.
After removing an
AWSIoTDataManager
, theAWSIoTDataManager
,AWSIoTMQTTClient
,AWSURLSessionManager
and other related entities were leaked.This fixes a retain cycle between the
AWSIoTMQTTClient
where it held a strong reference to theassociatedObject
theAWSIoTDataManager
which was holding a strong reference to themqttClient
. This makes theassociatedObject
reference weak.If an
AWSIoTDataManager
was disconnected before theconnectionAgeInSeconds
exceeded theminimumConnectionTime
theconnectionAgeTimer
was never invalidated and held a strong reference to theAWSIoTMQTTClient
(e.g.self
passed to the timer on creation of the timer). This fixes the issue by issuing aninvalidate
to the timer on the correct thread in the event the user requests a disconnect before reaching theminimumConnectionTime
.The
AWSURLSessionManager
creates and passesself
to anNSURLSession
but never invalidated the session to release the strong reference toself
.AWSNetworking
could be released but theAWSURLSessionManager
leaked being held by theNSURLSession
. This is fixed by having theAWSNetworking
let theAWSURLSessionManager
know it needs to invalidate the session when it is being released, as none of them should be needed after theAWSNetworking
creating them is released.The
reconnectTimer
was invalidated on whatever threaddisconnect
was called on rather than thereconnectThread
causing a memory leak; this is fixed by having thereconnectTimer
invalidated on the correct thread.