mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +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
8492a63052
commit
7e8eee6e3b
2 changed files with 18 additions and 5 deletions
|
@ -44,11 +44,24 @@ void LottieLoader::run(unsigned tid)
|
||||||
comp = parser.comp;
|
comp = parser.comp;
|
||||||
}
|
}
|
||||||
builder->build(comp);
|
builder->build(comp);
|
||||||
|
|
||||||
|
release();
|
||||||
}
|
}
|
||||||
rebuild = false;
|
rebuild = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LottieLoader::release()
|
||||||
|
{
|
||||||
|
if (copy) {
|
||||||
|
free((char*)content);
|
||||||
|
content = nullptr;
|
||||||
|
}
|
||||||
|
free(dirName);
|
||||||
|
dirName = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* External Class Implementation */
|
/* External Class Implementation */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -63,8 +76,7 @@ LottieLoader::~LottieLoader()
|
||||||
{
|
{
|
||||||
done();
|
done();
|
||||||
|
|
||||||
if (copy) free((char*)content);
|
release();
|
||||||
free(dirName);
|
|
||||||
|
|
||||||
//TODO: correct position?
|
//TODO: correct position?
|
||||||
delete(comp);
|
delete(comp);
|
||||||
|
@ -76,6 +88,7 @@ bool LottieLoader::header()
|
||||||
{
|
{
|
||||||
//A single thread doesn't need to perform intensive tasks.
|
//A single thread doesn't need to perform intensive tasks.
|
||||||
if (TaskScheduler::threads() == 0) {
|
if (TaskScheduler::threads() == 0) {
|
||||||
|
LoadModule::read();
|
||||||
run(0);
|
run(0);
|
||||||
if (comp) {
|
if (comp) {
|
||||||
w = static_cast<float>(comp->w);
|
w = static_cast<float>(comp->w);
|
||||||
|
@ -87,7 +100,6 @@ bool LottieLoader::header()
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LoadModule::read();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Quickly validate the given Lottie file without parsing in order to get the animation info.
|
//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()
|
bool LottieLoader::read()
|
||||||
{
|
{
|
||||||
if (!content || size == 0) return false;
|
|
||||||
|
|
||||||
//the loading has been already completed
|
//the loading has been already completed
|
||||||
if (!LoadModule::read()) return true;
|
if (!LoadModule::read()) return true;
|
||||||
|
|
||||||
|
if (!content || size == 0) return false;
|
||||||
|
|
||||||
TaskScheduler::request(this);
|
TaskScheduler::request(this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -77,6 +77,7 @@ private:
|
||||||
void clear();
|
void clear();
|
||||||
float startFrame();
|
float startFrame();
|
||||||
void run(unsigned tid) override;
|
void run(unsigned tid) override;
|
||||||
|
void release();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue