lottie: release memory immediately after loading is complete.

there is no need to retain the data,
as the Lottie source is not reusable
and is affected by the parsing mechanism.

issue: https://github.com/thorvg/thorvg/issues/2647
This commit is contained in:
Hermet Park 2024-10-17 11:15:56 +09:00 committed by Hermet Park
parent 8492a63052
commit 7e8eee6e3b
2 changed files with 18 additions and 5 deletions

View file

@ -44,11 +44,24 @@ void LottieLoader::run(unsigned tid)
comp = parser.comp;
}
builder->build(comp);
release();
}
rebuild = false;
}
void LottieLoader::release()
{
if (copy) {
free((char*)content);
content = nullptr;
}
free(dirName);
dirName = nullptr;
}
/************************************************************************/
/* External Class Implementation */
/************************************************************************/
@ -63,8 +76,7 @@ LottieLoader::~LottieLoader()
{
done();
if (copy) free((char*)content);
free(dirName);
release();
//TODO: correct position?
delete(comp);
@ -76,6 +88,7 @@ bool LottieLoader::header()
{
//A single thread doesn't need to perform intensive tasks.
if (TaskScheduler::threads() == 0) {
LoadModule::read();
run(0);
if (comp) {
w = static_cast<float>(comp->w);
@ -87,7 +100,6 @@ bool LottieLoader::header()
} else {
return false;
}
LoadModule::read();
}
//Quickly validate the given Lottie file without parsing in order to get the animation info.
@ -254,11 +266,11 @@ bool LottieLoader::resize(Paint* paint, float w, float h)
bool LottieLoader::read()
{
if (!content || size == 0) return false;
//the loading has been already completed
if (!LoadModule::read()) return true;
if (!content || size == 0) return false;
TaskScheduler::request(this);
return true;

View file

@ -77,6 +77,7 @@ private:
void clear();
float startFrame();
void run(unsigned tid) override;
void release();
};