Skip to content

Memory leaks #63

Closed
Closed
@dankinsoid

Description

@dankinsoid

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions