[osg-users] How to reduce the cache size limit of OSG ?

OpenSceneGraph Users osg-users at lists.openscenegraph.org
Tue May 26 11:37:27 PDT 2020

Hi Hui,

On Tuesday, 26 May 2020 10:36:18 UTC+1, Hui Li wrote:
> The codes looks like this: 
> ```
> root = GroupOfSwitch(); 
> viewer->setSceneData(root);
> while (!viewer->done()) {
>     root->removeChild(0); // Remove the point cloud 
>     pc = sensor.Capture();  // Get the point cloud
>     geo = CreateGeometryNode(pc);
>     root->addChild(geo); // Add the pointcloud 
>     viewer->frame();
> }
In "principle" this shouldn't cause unbounded memory growth but as you 
don't provide any details about the CreateGeometryNode() there is no way 
for use know what is going on there.  It could be that your leak it right 
there in that function call, or else where somewhere in your application.

While I can't comment about the details of your implementation the approach 
of removing, creating and adding new nodes and associated data each frame 
is really, really inefficient.

As much as possible you should try to reuse data.  For a point cloud 
application where the data is dynamic I would personally allocate a fixed 
number of Geometry nodes with fixed Vec3Array's within them and single 
DrawArray primitive set.  I'd allocate the Vec3Array to it's full size 
right up front and next change it's size.  The DrawArrays has a count value 
that you can set to specify how many vertices in the array need to be 
rendered and needn't be the whole length of the Vec3Aray.

With really large datasets I would chunk the data so rather one big 
osg::Geometry, I'd have say 10,000 vertices in each osg::Geometry.  I would 
also use VertexBufferObjects and avoid using DisplayLists.

Do this all correctly and you should get a good performance and no memory 


You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+unsubscribe at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/1d7f0fab-ad05-4c49-a37e-b09f6179dd0d%40googlegroups.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200526/523ec990/attachment.html>

More information about the osg-users mailing list