Samsung / rlottie

A platform independent standalone library that plays Lottie Animation.
Other
1.15k stars 223 forks source link

Add API for clearing the cache #526

Closed entdark closed 2 years ago

entdark commented 2 years ago

Hello, could you add an API for clearing the cache?

According to the code I can set cache size to 0 and it will just clear the cache holder: https://github.com/Samsung/rlottie/blob/c5961e6c480a47016fc58126fbc63cf9ec2b2edd/src/lottie/lottieloader.cpp#L71 But the proper cache clearing would be deleting cache holder if I understand it correctly: https://stackoverflow.com/questions/42529819/unordered-map-clear-does-not-release-heap-on-clear so setting cache size to 0 doesn't clear the cache.

Thank you.

smohantty commented 2 years ago

@entdark, As the link pointed the content of the cache will be cleared only the internal memory of the cache (hash) will not be released. Because the data inside of the cache is scalar and allocated as part of cache memory you will not see the reduction of heap when hash.clear() is called . But in our case cache is collection of shared_ptr , so actual resource is allocated separately not part of cache memory.

The cache will clear as expected when configureModelCacheSize(0) is called.

entdark commented 2 years ago

Thank you for the explanation.