Skip to content
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

Huge Amounts Of memory Leaks reported in XCode #95

Open
BarryDuggan opened this issue Jul 28, 2021 · 3 comments
Open

Huge Amounts Of memory Leaks reported in XCode #95

BarryDuggan opened this issue Jul 28, 2021 · 3 comments

Comments

@BarryDuggan
Copy link

Running on iOS 14.6
XCode 12.4

Related Issue

According to XCode there's a ton of retain cycles causing leaks in this Library.
Please see the attached screen shot for a better idea of what I'm talking about.

Screenshot 2021-07-28 at 14 48 50

@DispoKen
Copy link

DispoKen commented Jan 4, 2022

+1

@santanaNogueira
Copy link

Did anyone find the solution to this issue? Thanks in advance!

@zh-ios
Copy link

zh-ios commented Dec 12, 2024

I had fixed it

final class NTPConnection {
let address: SocketAddress
let timeout: TimeInterval
let maxRetries: Int
var logger: LogCallback?
private var throttleConnections: (() -> Void)?
func query(addresses: [SocketAddress],
config: NTPConfig,
logger: LogCallback?,
callbackQueue: DispatchQueue,
progress: @escaping NTPConnectionCallback) -> [NTPConnection] {
let connections = addresses.flatMap { address in
(0..<config.numberOfSamples).map { _ in
NTPConnection(address: address,
timeout: config.timeout,
maxRetries: config.maxRetries,
logger: logger)
}
}

    let onComplete: NTPConnectionCallback = {[weak self] connection, result in
        guard let self = self else {return}
        progress(connection, result)
        self.throttleConnections?()
    }

    self.throttleConnections = {
        let remainingConnections = connections.filter { $0.canRetry }
        let activeConnections = Array(remainingConnections[0..<min(config.maxConnections,
                                                                   remainingConnections.count)])
        activeConnections.forEach { $0.start(callbackQueue, onComplete: onComplete) }
    }
    self.throttleConnections?()
    return connections
}

query method you should use instance method and user weak self in the block .

NTPClient class

func query(addresses: [SocketAddress], host: String) {
var results: [String: [FrozenNetworkTimeResult]] = [:]
////// self.con = .....
self.con = NTPConnection(address: addresses[0], timeout: config.timeout, maxRetries: 3, logger: nil)
// / weak self
connections = self.con!.query(addresses: addresses, config: config, logger: logger, callbackQueue: queue, progress: {[weak self] connection , result in
guard let self = self else {return}
guard self.started && !self.finished else {
self.debugLog("Got NTP response after queue stopped: (result)")
return
}
.....

in the stop queue func you should set self.con = nil
func stopQueue() {
debugLog("Stopping queue")
startTime = nil
connections.forEach { $0.close(waitUntilFinished: true) }
connections = []
self.con = nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants