-
Notifications
You must be signed in to change notification settings - Fork 631
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
[Bug] - iOS: Thread not released by IMAP Session (each session allocates 560KB = standard thread side) #1993
Comments
hello,I had the same problem,Did you solve it? |
Not really, just using a workaround by keeping the connection object all the time, and only releasing it on any exception (memory = +560KB after each exception). I keep global connection in actor, like: actor IMAPSession {
// static func clearSessionMemory() async { and after IMAP operation in each IMAP catch I have: do { |
We have code here to terminate the thread after a second or so: |
Thank You Hoa for the MailCore work! |
dinvuh can you explain the method below that one line 238 why the release #2 happens after sending start thread again? Is that correct or should it be before resending startThread() in the if statement? |
I was looking though the code of MCOperationQueue.cpp few times and could not find why - but I think cancelAllOperations() somehow does not stop the thread, maybe the concurrent logic does not trigger the checkRunningAfterDelay(). Somehow the thread memory is not released, maybe the thread is stopped. Second observation - as per the code when operations are done, the code in runOperations() - it should also release thread on it's own (I think), but this does not happen either. I am calling cancelAllOperations() after operations are done. Could we maybe have another call clearAfterCancelAllOperations() - doing the thread cleanup once we know the operations are done? Also these lines are a bit different (could 143 be the reason for not releasing memory after the thread): |
Summary
On iOS in Xcode OperationQueue Thread is not released by IMAP Session (each session allocates 560KB = standard thread size)
These threads stay in memory, and finally app goes out of memory. Might be because [dispatch_release] is not supported anymore or maybe something holds in [DispatchQueue] or the tasks count is not released to zero (so it will not get cleared), or something is not [nil]'ed to release by iOS.
Platform(s)
iOS iPhone 13
XCode
Happens on Mail Server
outlook
Hotmail
And few others - hosted mail servers
Piece of code
To reproduce run it on timer (all class below):
public class MapViewModel {
public var TAG:String = "MapViewModel : "
var timer: Timer? = nil
public func StopTaskScheduler(){
if (self.timer != nil) {
self.timer!.invalidate()
self.timer = nil
}
}
// you can run it as closure
imapConnect()
// you can run it async - same result as closure
Task { [weak self] in
guard let strongSelf = self else {
return
}
await strongSelf.imapConnectAsync()
}
}
}
Actual outcome
MailCore does not release IMAP Session thread
** Logs**
Please see the screenshot
Expected outcome
MailCore should release IMAP Session thread
The text was updated successfully, but these errors were encountered: