The problem reason was that I used the old version of lottie-ios pod – 3.1.8. In the old version, the BundleImageProvider had the static cache property
static var cache = [String: UIImage]()
So even when all instances of BundleImageProvider
are deinitialized, this property is still in memory because it's static. There is no clearCache method. And the property is not public. So I can't access it directly. In version 3.1.9, they removed this property, so the problem is solved.
But if you still need to use the old version there is another solution
The init of the AnimationView has imageProvider: AnimationImageProvider
argument. The AnimationImageProvider
is a protocol. If the passed property is nil the BundleImageProvider
is used by default. You may create your own implementation of AnimationImageProvider
and use it. You may copy the implementation of the BundleImageProvider
and then do one of two actions:
- make the
cache
property non-static
- leave the
cache
property static, but add the clearCache
method.
I prefer the first one because you won't need to manually handle cache clear.