memory leak

mickey

30-01-2009 06:15:32

Hi

This is all my code:

Caelum::CaelumSystem::CaelumComponent componentMask;
componentMask = static_cast<Caelum::CaelumSystem::CaelumComponent> (Caelum::CaelumSystem::CAELUM_COMPONENT_CLOUDS);

gCaelumSystem = new Caelum::CaelumSystem (Root::getSingletonPtr(), mSceneMgr, componentMask);

And on my destructor:

if (gCaelumSystem)
{
gCaelumSystem->shutdown (false);
gCaelumSystem = 0;
}

And caelum will leak a lot of memory.

Any idea?

cdleonard

30-01-2009 08:27:28

You're doing it wrong; see http://caelum.sourceforge.net/doc/0.4.0 ... 501430c61a for the shutdown method. You already said in another topic you don't add CaelumSystem as a FrameListener; so leaks are to be expected. This is by design.

You should just call "delete gCaelumSystem" in shutdown code; that should work in your case. Or you can just hold CaelumSystem inside an auto_ptr for extra safety. I personally try to avoid all manual deletions when possible.

mickey

02-02-2009 09:38:57

Hi cdleonard

Thanks for your reply.

I did what you said - modified my destructor code:

if (gCaelumSystem)
{
delete gCaelumSystem;
gCaelumSystem = NULL;
}

I also tried calling shutdown(true) instead of false earlier. Didn't help.

I still get memory leak?

cdleonard

03-02-2009 17:54:51

I'd don't know then; it should clean up properly. What makes you sure that Caelum leaks memory?

mickey

04-02-2009 05:33:04

Hi cdleonard

I have eveything enabled but caelum and when i quit my app, there's no memory leak. whenever i add caelum to my game and shuts down, i get memory leak report.

There's actually one more issue but i was hoping this first issue was solve first. The other issue is i get a crash when deleting the caelum object if i create a 2nd clour layer:

Caelum::FlatCloudLayer* layer = gCaelumSystem->getCloudSystem ()->createLayerAtHeight (1800.f);
layer->setFadeDistances( farClip * 0.8f, farClip );
layer->setCloudCover (0.7f);
layer->_ensureGeometry();
gCaelumSystem->getCloudSystem()->addLayer(layer);

On the call to delete gCaelumSystem on my ExampleApplication destructor, my application will crash. I also tried deleting the 2nd cloud layer manually prior to delete gCaelumSystem, didn't work.

I could try somethings for you if you want, just tell me which ones so we can nail down the problem.

cdleonard

04-02-2009 11:00:11

The createLayerAtHeight adds the layer before it returns; you don't need to do addLayer. When CaelumSystem shuts down it deletes all added layers and you get a double free which causes a crash.