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
BundleImageProviderare 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: AnimationImageProviderargument. TheAnimationImageProvideris a protocol. If the passed property is nil theBundleImageProvideris used by default. You may create your own implementation ofAnimationImageProviderand use it. You may copy the implementation of theBundleImageProviderand then do one of two actions:cacheproperty non-staticcacheproperty static, but add theclearCachemethod. I prefer the first one because you won't need to manually handle cache clear.