Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak when using assimp to read dae file #2182

Closed
Dzhange opened this issue Oct 14, 2018 · 13 comments
Closed

Memory leak when using assimp to read dae file #2182

Dzhange opened this issue Oct 14, 2018 · 13 comments
Labels
Bug

Comments

@Dzhange
Copy link

@Dzhange Dzhange commented Oct 14, 2018

        string path = "/sdcard/Resources//somefile.dae";
        const aiScene* scene = importer_->ReadFile( path,
                                                  aiProcess_CalcTangentSpace       |
                                                  aiProcess_Triangulate            |
                                                  aiProcess_JoinIdenticalVertices  |
                                                  aiProcess_SortByPType);
        importer_->FreeScene();
        delete importer_;

when use these code to read a dae model, the memory usage reached 240MB, and remained 100MB after importer->freescene and delete importer.
Is it a bug of assimp?

@turol
Copy link
Member

@turol turol commented Oct 14, 2018

Can you share your test model?

@Dzhange
Copy link
Author

@Dzhange Dzhange commented Oct 14, 2018

sorry, I can't offer that to you... I have some blendshape operation in that model, does that matter?

@turol
Copy link
Member

@turol turol commented Oct 14, 2018

I don't know. If you make a (preferably minimal) test file using that feature I can check it. Without it this bug is pretty much impossible to fix.

@Dzhange
Copy link
Author

@Dzhange Dzhange commented Oct 14, 2018

I'll try to reproduce that memory leak with another model.

@kimkulling kimkulling added the Bug label Oct 15, 2018
@kimkulling
Copy link
Member

@kimkulling kimkulling commented Oct 15, 2018

Thanks a lot for the help. You can use the CI to get a list of open leaks when you create a testcase for it.

@ZhengzhongSun
Copy link

@ZhengzhongSun ZhengzhongSun commented Oct 15, 2018

I met the same problems. I test 3 dae models, they both have memory leak after release it. I use the same test program as @Dzhange. I run the program on an android phone.

  1. The first model is with blendshape and bone. Before loading, the memory of phone is 24.9MB. After loading, the memory of phone is 450.1MB. Then calling importer_->FreeScene() and delete importer_, the memory of phone is still 122.4MB. It seems the memory leak is nearly 100MB.
  2. The second model is just mesh, without blendshape and bone. Before loading, the memory of phone is 23.6MB. After loading, the memory of phone is 228.6MB. Then calling importer_->FreeScene() and delete importer_, the memory of phone is still 65.6MB. It seems the memory leak is about 40MB.
  3. The third model is also just mesh, but it's larger than the second one. Before loading, the memory of phone is 27.5MB. After loading, the memory of phone is 0.8GB. Then calling importer_->FreeScene() and delete importer_, the memory of phone is 0.2GB. It seems the memory leak is nearly 200MB.

From the experiment, we can see the memory leak is a constant percent. It's about 25%.
importer_->FreeScene();
delete importer_;
Are these codes enough for release memory in this simple case?
Here are our 3 test dae models, you can do some test on it. @turol
https://drive.google.com/file/d/1WCA9s0uMoobWZD7tTXV9YVYnG4OJ0g3g/view?usp=sharing
What's the CI? How to use it? @kimkulling
Thank you very much!
Any response will be appreciated!

Dobbie

@turol
Copy link
Member

@turol turol commented Oct 16, 2018

Several memory leaks, this is the biggest:

48,682,024 (12,960 direct, 48,669,064 indirect) bytes in 10 blocks are definitely lost in loss record 13 of 13
   at 0x4835E2F: operator new(unsigned long) (vg_replace_malloc.c:334)
   by 0x5B7BAF: Assimp::ColladaLoader::CreateMesh(Assimp::ColladaParser const&, Assimp::Collada::Mesh const*, Assimp::Collada::SubMesh const&, Assimp::Collada::Controller const*, unsigned long, unsigned long) (ColladaLoader.cpp:599)
   by 0x5B87AC: Assimp::ColladaLoader::CreateMesh(Assimp::ColladaParser const&, Assimp::Collada::Mesh const*, Assimp::Collada::SubMesh const&, Assimp::Collada::Controller const*, unsigned long, unsigned long) (ColladaLoader.cpp:714)
   by 0x5B9F8C: Assimp::ColladaLoader::BuildMeshesForNode(Assimp::ColladaParser const&, Assimp::Collada::Node const*, aiNode*) (ColladaLoader.cpp:544)
   by 0x5BA44A: Assimp::ColladaLoader::BuildHierarchy(Assimp::ColladaParser const&, Assimp::Collada::Node const*) (ColladaLoader.cpp:266)
   by 0x5BA3B5: Assimp::ColladaLoader::BuildHierarchy(Assimp::ColladaParser const&, Assimp::Collada::Node const*) (ColladaLoader.cpp:254)
   by 0x5BA3B5: Assimp::ColladaLoader::BuildHierarchy(Assimp::ColladaParser const&, Assimp::Collada::Node const*) (ColladaLoader.cpp:254)
   by 0x5C01BD: Assimp::ColladaLoader::InternReadFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, aiScene*, Assimp::IOSystem*) (ColladaLoader.cpp:179)
   by 0x54B4F2: Assimp::BaseImporter::ReadFile(Assimp::Importer const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Assimp::IOSystem*) (BaseImporter.cpp:101)
   by 0x6E4C83: Assimp::Importer::ReadFile(char const*, unsigned int) (Importer.cpp:648)

There are others but they're probably a symptom of this one. The mesh pointer handling in ColladaLoader.cpp looks suspect, it might be possible to clean it up with judicious use of unique_ptr.

@ZhengzhongSun
Copy link

@ZhengzhongSun ZhengzhongSun commented Oct 16, 2018

Several memory leaks, this is the biggest:

48,682,024 (12,960 direct, 48,669,064 indirect) bytes in 10 blocks are definitely lost in loss record 13 of 13
   at 0x4835E2F: operator new(unsigned long) (vg_replace_malloc.c:334)
   by 0x5B7BAF: Assimp::ColladaLoader::CreateMesh(Assimp::ColladaParser const&, Assimp::Collada::Mesh const*, Assimp::Collada::SubMesh const&, Assimp::Collada::Controller const*, unsigned long, unsigned long) (ColladaLoader.cpp:599)
   by 0x5B87AC: Assimp::ColladaLoader::CreateMesh(Assimp::ColladaParser const&, Assimp::Collada::Mesh const*, Assimp::Collada::SubMesh const&, Assimp::Collada::Controller const*, unsigned long, unsigned long) (ColladaLoader.cpp:714)
   by 0x5B9F8C: Assimp::ColladaLoader::BuildMeshesForNode(Assimp::ColladaParser const&, Assimp::Collada::Node const*, aiNode*) (ColladaLoader.cpp:544)
   by 0x5BA44A: Assimp::ColladaLoader::BuildHierarchy(Assimp::ColladaParser const&, Assimp::Collada::Node const*) (ColladaLoader.cpp:266)
   by 0x5BA3B5: Assimp::ColladaLoader::BuildHierarchy(Assimp::ColladaParser const&, Assimp::Collada::Node const*) (ColladaLoader.cpp:254)
   by 0x5BA3B5: Assimp::ColladaLoader::BuildHierarchy(Assimp::ColladaParser const&, Assimp::Collada::Node const*) (ColladaLoader.cpp:254)
   by 0x5C01BD: Assimp::ColladaLoader::InternReadFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, aiScene*, Assimp::IOSystem*) (ColladaLoader.cpp:179)
   by 0x54B4F2: Assimp::BaseImporter::ReadFile(Assimp::Importer const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Assimp::IOSystem*) (BaseImporter.cpp:101)
   by 0x6E4C83: Assimp::Importer::ReadFile(char const*, unsigned int) (Importer.cpp:648)

There are others but they're probably a symptom of this one. The mesh pointer handling in ColladaLoader.cpp looks suspect, it might be possible to clean it up with judicious use of unique_ptr.

So the assimp library actually has memory leak problems indeed, it really confusing me in my project. Could you think it's easy to solve in a short time? Thank you!

@Dzhange
Copy link
Author

@Dzhange Dzhange commented Oct 17, 2018

Any Progress?
I tried to use .fbx model instead,
but the memory leak still exist, and even worse,
I failed to get aiAnimMesh from the .fbx model. here is my code

    Assimp::Importer *importer = new Assimp::Importer;

    const aiScene* scene = importer->ReadFile( "/Resources/somefile.fbx",
                                                 aiProcess_CalcTangentSpace       |
                                                 aiProcess_Triangulate            |
                                                 aiProcess_JoinIdenticalVertices  |
                                                 aiProcess_SortByPType);

    for (unsigned int i = 0; i < scene->mNumMeshes; i++) {
        aiAnimMesh **ani =  scene->mMeshes[i]->mAnimMeshes;
        if (ani!= nullptr) {
            cout << "aianimmesh exists" << endl;
        }
    
    }
    delete importer;

@Dzhange
Copy link
Author

@Dzhange Dzhange commented Oct 24, 2018

Hi!
This memory leak matters a lot to me, so I'm wondering how soon can this bug get fixed?

I'm also looking for alternative tools that can help me load models with blend shape (in the format of .fbx or .dae), but though I've been doing research for a whole week, I made no progress. Can you give me some suggestions?

Thank you for your help!

@Dzhange
Copy link
Author

@Dzhange Dzhange commented Jul 6, 2019

After almost a year, I come here hopelessly with a failed project caused by this memory leak, all I wanna know is whether this bug is fixed or not?

@kimkulling
Copy link
Member

@kimkulling kimkulling commented Jul 6, 2019

@kimkulling
Copy link
Member

@kimkulling kimkulling commented Jul 9, 2019

Closed by #2535

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug
Projects
None yet
Development

No branches or pull requests

4 participants