memory leak in osgEaarth

classic Classic list List threaded Threaded
13 messages Options
brett brett
Reply | Threaded
Open this post in threaded view
|

memory leak in osgEaarth

Hi,

I'm using osgEarth rev281, osg 2.6.0, vc7 and XP.

I have a reproducable memory leak. Basically, I'm thinking osgEarth isn't cleaning up textures. Can this be possible?

Here's the source code to a test app that proves this. Basically, i create an osgviewer, add a .earth file and then delete the viewer.

I use windows task manager to look at the memory usage. When I run the app, memory usage goes up as I move around. Makes sense. When I hit "escape" exiting the viewer and deleting it, memory usage goes down, but not back to pre osgEarth loaded levels.

Thoughts?

Thanks,
Brett

#include <osg/Node>
#include <osgDB/ReadFile> 
#include <osgViewer/Viewer>
#include <osgViewer/CompositeViewer>
#include <osgViewer/View>
#include <osgGA/TrackballManipulator>
#include <conio.h>

   main()
   {
      // create viewer
      osgViewer::Viewer* viewer = new osgViewer::Viewer;
      viewer->setUpViewOnSingleScreen(0);      
      viewer->setCameraManipulator(new osgGA::TrackballManipulator());

      std::string modelPath =
         "C:\\servers\\arc_shaded_relief.earth";

      {
         // create an osgEarth node. Add it to the scene graph and let the ref pointer go out of scope.
         osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(modelPath);
         viewer->setSceneData(node.get());
      }

      // render a frame
      viewer->realize();
      while(!viewer->done())
      {
         viewer->frame();
      }

      // delete viewer.
      delete viewer;
      viewer = 0;

      std::cout<<"Look at memory usage of application. Press any key to continue...";
      std::cin.ignore(0,'\n');
      getch();

   }
jasonbeverage jasonbeverage
Reply | Threaded
Open this post in threaded view
|

Re: memory leak in osgEaarth

Hi Brett,

I believe this comes down to the fact that osgEarth caches the TileBuilders as they are created in a static map but doesn't currently delete the TileBulider from the cache automatically.  If your app is just loading a single globe, then this typically won't be a problem, but if you are trying to load and unload different globes constantly, I can see where the leak would be an issue.  I'll see if I can't find a simple solution and get it to you soon.

Thanks!

Jason

On Thu, Mar 19, 2009 at 5:00 PM, brett (via Nabble) - No Reply <[hidden email]> wrote:
Hi,

I'm using osgEarth rev281, osg 2.6.0, vc7 and XP.

I have a reproducable memory leak. Basically, I'm thinking osgEarth isn't cleaning up textures. Can this be possible?

Here's the source code to a test app that proves this. Basically, i create an osgviewer, add a .earth file and then delete the viewer.

I use windows task manager to look at the memory usage. When I run the app, memory usage goes up as I move around. Makes sense. When I hit "escape" exiting the viewer and deleting it, memory usage goes down, but not back to pre osgEarth loaded levels.

Thoughts?

Thanks,
Brett

#include <osg/Node>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgViewer/CompositeViewer>
#include <osgViewer/View>
#include <osgGA/TrackballManipulator>
#include <conio.h>

   main()
   {
      // create viewer
      osgViewer::Viewer* viewer = new osgViewer::Viewer;
      viewer->setUpViewOnSingleScreen(0);      
      viewer->setCameraManipulator(new osgGA::TrackballManipulator());

      std::string modelPath =
         "C:\\myData\\dev\\vrv\\vrv1.0\\makIG\\userData\\servers\\arc_shaded_relief.earth";

      {
         // create an osgEarth node. Add it to the scene graph and let the ref pointer go out of scope.
         osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(modelPath);
         viewer->setSceneData(node.get());
      }

      // render a frame
      viewer->realize();
      while(!viewer->done())
      {
         viewer->frame();
      }

      // delete viewer.
      delete viewer;
      viewer = 0;

      std::cout<<"Look at memory usage of application. Press any key to continue...";
      std::cin.ignore(0,'\n');
      getch();

   }



View message @ http://n2.nabble.com/memory-leak-in-osgEaarth-tp2505392p2505392.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.


brett brett
Reply | Threaded
Open this post in threaded view
|

Re: memory leak in osgEaarth

Jason,

We load terrains like word (openOffice for me) opens .doc files. ;)

Any help would be appreciated!

Thanks,
Brett
brett brett
Reply | Threaded
Open this post in threaded view
|

Re: memory leak in osgEaarth

Jason,

Some more info...

Using gDebugger we've determined that no texture objects are deleted when a terrain is unloaded. Also there clearly is some caching of something since the geometry objects are only deleted when you reload the identical terrain.

Thanks,
Brett
jasonbeverage jasonbeverage
Reply | Threaded
Open this post in threaded view
|

Re: memory leak in osgEaarth

Hi Brett,

I've just committed some changes to the way that osgEarth works to allow nodes to be deleted automatically.  The nodes are getting deleted automatically just like you would expect now.

I wrote a quick little program to test this out.  This example also shows how to safely remove the current globe and load a new globe.  One thing I've noticed is that the DatabasePager really doesn't like it when you delete the destination node out from under it while its trying to work, so this example shows one way to wait for the pager to complete its work before you load a new node.

Let me know how this works out for you!

Jason

On Thu, Mar 19, 2009 at 7:39 PM, brett (via Nabble) - No Reply <[hidden email]> wrote:
Jason,

Some more info...

Using gDebugger we've determined that no texture objects are deleted when a terrain is unloaded. Also there clearly is some caching of something since the geometry objects are only deleted when you reload the identical terrain.

Thanks,
Brett


View message @ http://n2.nabble.com/memory-leak-in-osgEaarth-tp2505392p2506120.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.



osgearth_swapfiles.cpp (6K) Download Attachment
brett brett
Reply | Threaded
Open this post in threaded view
|

Re: memory leak in osgEaarth

Jason,

OK I try that out. The stuff about the SwapFileCallback... Is that something that should/ could be done automatically by osgEarth?

Thanks,
Brett
jasonbeverage jasonbeverage
Reply | Threaded
Open this post in threaded view
|

Re: memory leak in osgEaarth

Hi Brett,

The SwapFileCallback is just an example on how you need to manipulate the DatabasePager to ensure that it doens't have issues when you are switching paged nodes in and out.  I don't think it would be appropriate for osgEarth to try to do this automatically since it's really an application level operation. For instance, if you're just loading a single globe that will stick around for your whole application, then you don't need to worry about anything.

Thanks!

Jason

On Fri, Mar 20, 2009 at 12:26 PM, brett (via Nabble) - No Reply <[hidden email]> wrote:
Jason,

OK I try that out. The stuff about the SwapFileCallback... Is that something that should/ could be done automatically by osgEarth?

Thanks,
Brett


View message @ http://n2.nabble.com/memory-leak-in-osgEaarth-tp2505392p2509829.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.


brett brett
Reply | Threaded
Open this post in threaded view
|

Re: memory leak in osgEaarth

Hey,

So I'm getting some compiler errors with rev296 and OSG 2.6.0. It seems like some of the openThreads stuff has changed. Am I doing something wrong or are these changes not compatible osg 2.6.0?

Thanks,
Brett
brett brett
Reply | Threaded
Open this post in threaded view
|

Re: memory leak in osgEaarth

This may be my fault. Looking into it...
jasonbeverage jasonbeverage
Reply | Threaded
Open this post in threaded view
|

Re: memory leak in osgEaarth

Hi Brett,

Do an svn update, I added an include of OpenThreads/ReentrantMutex in TileBuilder.cpp to fix the 2.6 build.

Thanks!

Jason

On Fri, Mar 20, 2009 at 2:10 PM, brett (via Nabble) - No Reply <[hidden email]> wrote:
This may be my fault. Looking into it...


View message @ http://n2.nabble.com/memory-leak-in-osgEaarth-tp2505392p2510376.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.


brett brett
Reply | Threaded
Open this post in threaded view
|

Re: memory leak in osgEaarth

In reply to this post by brett
At least one change is needed...


Add to TileBuilder.cpp

#include <OpenThreads/ReentrantMutex>

Now I'm just getting linking errors with Expat. This may be my fault
brett brett
Reply | Threaded
Open this post in threaded view
|

Re: memory leak in osgEaarth

Also, the osgEarth module needs to link against Expat now.
brett brett
Reply | Threaded
Open this post in threaded view
|

Re: memory leak in osgEaarth

Cool. Things are building. I just dropped in the new dlls. The first terrain unloads (partially) and then next one doesn't get more than the highest lod imagery. I'll try adding the callback stuff now.

Thanks,
Brett