Skip to content

Memory leak in DotLottieAnimationView due to strong reference cycle with Coordinator #73

@AbdulrahmanQasem95

Description

@AbdulrahmanQasem95

Hi team,

First of all, thank you for your great work on this library — it’s been very helpful in my project.

I’ve encountered a memory leak in DotLottieAnimationView caused by a strong reference cycle between DotLottieAnimationView and its Coordinator.

Both DotLottieAnimationView and Coordinator hold strong references to each other:

public class DotLottieAnimationView: UIView, DotLottie {
    private var coordinator: Coordinator!

    private func setupMetalView() {
        self.coordinator = Coordinator(self, mtkView: mtkView)
    }
}
public class Coordinator: NSObject, MTKViewDelegate {
    private var parent: DotLottie

    init(_ parent: DotLottie, mtkView: MTKView) {
        self.parent = parent
    }
}

Because parent in Coordinator is a strong reference and DotLottieAnimationView holds coordinator strongly, neither object is ever deallocated.

This becomes a significant issue when DotLottieAnimationView is used in a scrolling UICollectionView or UITableView (e.g., a grid of animations). Over time, hundreds of DotLottieAnimationView instances accumulate in memory and are never released.

Best regards,
Abdulrahman Qasem

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions