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

Liquid fun memory leak #3

Closed
scratali opened this issue Mar 8, 2014 · 2 comments
Closed

Liquid fun memory leak #3

scratali opened this issue Mar 8, 2014 · 2 comments
Labels

Comments

@scratali
Copy link

scratali commented Mar 8, 2014

Hi
I just put the following lines in main() in Testbed for memory leak check:

if defined(_WIN32)

// Enable memory-leak reports
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));

endif

the result shows large memory leak.

@scratali
Copy link
Author

scratali commented Mar 9, 2014

Hi
I tested liquid fun in my own code. Here's my initial code:

b2ParticleGroupDef pd;
pd.flags = b2_waterParticle;
b2PolygonShape shape;
shape.SetAsBox(hx, hy, vCenter, 0.0);
pd.shape = &shape;
pWorld->CreateParticleGroup(pd);

After this, I got some like 9 or 10 memory leak reports. Using visual leak detector, I was able to track down which buffers are not freed and here's the list (which I free manually):

free(pWorld->m_particleSystem.m_flagsBuffer.data);
free(pWorld->m_particleSystem.m_positionBuffer.data);
free(pWorld->m_particleSystem.m_velocityBuffer.data);
free(pWorld->m_particleSystem.m_accumulationBuffer);
free(pWorld->m_particleSystem.m_colorBuffer.data);
free(pWorld->m_particleSystem.m_groupBuffer);
free(pWorld->m_particleSystem.m_userDataBuffer.data);
free(pWorld->m_particleSystem.m_contactBuffer);
free(pWorld->m_particleSystem.m_proxyBuffer);
free(pWorld->m_particleSystem.m_bodyContactBuffer);

All getting memory through ReallocateBuffer(). I don't know if this is a bug in ReallocateBuffer or box2d's own blockAllocator memory allocation system.

Btw, great API!

Thanks

@stewartmiles
Copy link
Contributor

This has been fixed in a couple of ways.
Firstly, we modified b2ParticleSystem to explicitly free all allocated memory. In addition, we fixed b2BlockAllocator to free anything it allocates on destruction since large blocks would be leaked.
https://github.com/google/liquidfun/releases/tag/v1.0.0

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

No branches or pull requests

2 participants