mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
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:
parent
661bdeb9b7
commit
d0f18e741d
2 changed files with 18 additions and 5 deletions
|
@ -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.
|
||||
|
@ -253,11 +265,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;
|
||||
|
|
|
@ -77,6 +77,7 @@ private:
|
|||
void clear();
|
||||
float startFrame();
|
||||
void run(unsigned tid) override;
|
||||
void release();
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue