Closed
Description
I looked at the code and noticed strong reference cycles:
/// Lazy initialized `QueryAPI`.
public lazy var queryAPI: QueryAPI = {
QueryAPI(client: self)
}()
/// Lazy initialized `DeleteAPI`.
public lazy var deleteAPI: DeleteAPI = {
DeleteAPI(client: self)
}()
/// Lazy initialized `InvokableScriptsAPI`.
public lazy var invokableScriptsApi: InvokableScriptsAPI = {
InvokableScriptsAPI(client: self)
}()
and inside QueryAPI, DeleteAPI, InvokableScriptsAPI:
/// Shared client.
private let client: InfluxDBClient
So QueryAPI, DeleteAPI, InvokableScriptsAPI have a strong reference to the client and the client has strong references to them, creating a reference cycle that leads to a memory leak. None of these objects can be deinitialized.
Since none of these classes store anything mutable, I suggest using structs instead of classes here and making these properties computed:
public var queryAPI: QueryAPI {
QueryAPI(client: self)
}
public var deleteAPI: DeleteAPI {
DeleteAPI(client: self)
}
public var invokableScriptsApi: InvokableScriptsAPI {
InvokableScriptsAPI(client: self)
}
InfluxDBClient
could also be a struct, and it would be ideal if all these types conformed to the Sendable
protocol.
Metadata
Metadata
Assignees
Labels
No labels