Hi,

I'm building a little app that constructs PagedLOD nodes for a set of terrain tiles based on their extents. The idea is to move around the database and have certain tiles paged in and as I move away from them have them paged out of memory.

Anyways, I've noticed that although I'm calling removeExpiredChildren() on each of my PagedLOD objects some memory is being freed but a lot of memory isn't. I'll move outside of the paging radius of all of my tiles, for example, and the NodeList returned from removeExpiredChildren() will indicate that the nodes have been removed yet memory usage only appears to be going down slightly (and the nodes are much quicker to page back in, probably because memory isn't being freed).

I'm not sure what I'm doing wrong to cause (or not cause) the memory to be freed. I have verified that getNumChildren() for each of the PagedLOD's after I move away from all of the terrain segments goes to 0 (after removeExpiredChildren() is called). I'm running OSG 1.2. Here's the basics of the code. Any advice would be appreciated.

==========

   // Set up the viewer
   osgProducer::Viewer viewer(args);
   viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);

   // Tell the viewer what to display for a help message
   viewer.getUsage(*args.getApplicationUsage());

   osg::ref_ptr<osg::Group> group = new osg::Group();
   group->setName("plod toplevel node");

   vector< osg::ref_ptr<osg::PagedLOD> > plods;
   for(unsigned int i=0; i < terrain_filenames.size(); ++i)
   {
      // obtain center position
      double radius = bboxes[i].radius();
      osg::Vec3 center = bboxes[i].center();

      // setup new lod
      osg::ref_ptr<osg::PagedLOD> lod = new osg::PagedLOD();
      lod->setName("plod for " + terrain_filenames[i]);
      lod->setRangeMode(osg::LOD::DISTANCE_FROM_EYE_POINT);
      lod->setFileName(0, terrain_filenames[i]);
      lod->setCenter(center);
      lod->setRadius(radius);
      lod->setRange(0, 0.0f, bboxes[i].radius() * 5.0); // FIXME

      group->addChild(lod.get());
   }

   // Optimize the scene
   osgUtil::Optimizer optimizer;
   optimizer.optimize(group.get());

   // set the scene to render
   viewer.setSceneData(group.get());

   osg::Timer_t start_time = osg::Timer().tick();
   osg::Timer_t last_output = osg::Timer().tick();

   // Realize the viewer
   viewer.realize();
   while( !viewer.done() )
   {
      viewer.sync();
      viewer.update();

      //
      // Debuging code to call removeExpiredChildren() every so often
      //
      osg::Timer_t cur_time = osg::Timer().tick();
      if ( osg::Timer().delta_s(last_output, cur_time) > 0.2)
      {
         last_output = cur_time;

const double secs_since_start = osg::Timer().getSecondsPerTick() * (cur_time - start_time);
         double a_while_back = secs_since_start - 10.0;
         if(a_while_back < 0) a_while_back = 0;

         for(unsigned int i=0; i<group->getNumChildren(); ++i)
         {
            osg::NodeList nl;
osg::PagedLOD *lod = static_cast<osg::PagedLOD*> (group->getChild(i)); bool removed_something = lod->removeExpiredChildren(a_while_back, nl);
            if(removed_something)
            {
cout << "REMOVED STUFF. num children of lod " << lod->getName() << " is now " << lod->getNumChildren() << endl;
               for(uint i=0; i<nl.size(); ++i)
               {
cout << "nl[" << i << "] name = " << nl[i]->getName() << endl; cout << "ref count = " << nl[i]->referenceCount() << endl;
               }
            }
         }
      }






--
Philip Lowman
Simulation Development Engineer, Modeling and Simulation Technology
General Dynamics Land Systems
http://www.gdls.com
_______________________________________________
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to