I have a view controller with AnimationView
(the class of lottie-ios
pod). The animation takes too much memory (about 800 MB). But the problem is that,after the view controller is dismissed, the memory is still full.
The animation view is created as following:
var mainAnimation = AnimationView(name: "my_animation_name")
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. TheAnimationImageProvider
is a protocol. If the passed property is nil theBundleImageProvider
is used by default. You may create your own implementation ofAnimationImageProvider
and use it. You may copy the implementation of theBundleImageProvider
and then do one of two actions:cache
property non-staticcache
property static, but add theclearCache
method. I prefer the first one because you won't need to manually handle cache clear.