OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

How to track down memory leaks?


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
OmegaDoom
Newbie


Joined: 25 Jun 2018
Posts: 16

PostPosted: Wed Jul 11, 2018 1:07 pm    Post subject:
How to track down memory leaks?
Reply with quote

Hi.

I'm facing memory consumption increase If I remove and create new nodes every frame. I don't have it if I use pools but this issue is nagging me anyway. Memory consumption increases gradually and does't stop although visually a scene looks ok and no lags. I have found this interesting post -
OpenSceneGraph memory usage when resetting scene

Does this cache really exist? If it does then how to track down memory leaks in such situation?
Back to top
View user's profile Send private message
sbrkopac
Newbie


Joined: 14 Jun 2018
Posts: 8

PostPosted: Wed Jul 11, 2018 3:28 pm    Post subject:
Reply with quote

Not really sure what you mean by memory leaks. If you don't want the cache to cache any objects then disable it. This will have the trade off of having to parse / upload a node every time you remove it and then re-add it.
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12094

PostPosted: Wed Jul 11, 2018 4:21 pm    Post subject:
How to track down memory leaks?
Reply with quote

HI Igor,

You don't provide enough information to know what might be causing the
increasing in memory so we can't provide any specific guidance. In
general the OSG's memory management is pretty solid, there are areas
where data is cached either explicitly or implicitly due to
restrictions due to the GL memroy model.

In the osgDB::FileCache but this is only associated with loading and
reusing loaded models and is off by default so unless you have
specifically enabled this and loading adding to the scene graph then
removing from the scene graph.

Then there is the OpenGL side, to rendering with OpenGL you have to
create texture objects, buffer objects and display lists that are all
cached within OpenGL driver memory, when you delete the corresponding
scene graph objects these GL objects can't be deleted right away so
the OSG caches them and then flushes these caches during the next
frame. It does like flush in a lazy way though, and will attempt to
reuse GL objects when you request new GL objects of the same size and
format of the cached GL objects. This reuse of cached and waiting
to be deleted GL objects really helps with performance for dynamic
scene graphs.

While this caching on the GL side can initially grow it's not a leak,
it's just delayed clean up and it should stabilize after a while.

Then there is bugs in your own program, or perhaps even issues with
how you are measuring the "leak". We don't have your program in front
of us, we don't have your data, or any of your tests results so
basically can't really do anything more - you are the only with all
the tools in front of you.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
OmegaDoom
Newbie


Joined: 25 Jun 2018
Posts: 16

PostPosted: Thu Jul 12, 2018 3:15 pm    Post subject:
Reply with quote

Hello Robert.

I have found the memory leak cause. Look like I don't understand how osg works.
I have a root node and its child node. I add UpdateCallback to the root node and inside this callback i remove child nod's drawables and add another ones. I check reference count before I remove them and it's 2 for some reason. My remove decreases it on 1 but it's not enough. Looks like viewer or something else keeps these drawables and therefore memleak happens.

I checked reference count of drawables after I add them to child's node and it's always 1 but when drawables come again to UpdateCallback it becomes 2.
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12094

PostPosted: Thu Jul 12, 2018 3:58 pm    Post subject:
How to track down memory leaks?
Reply with quote

Hi Igor,

On Thu, 12 Jul 2018 at 16:24, Igor Spiridonov <> wrote:
Quote:
I have found the memory leak cause. Look like I don't understand how osg works.
I have a root node and its child node. I add UpdateCallback to the root node and inside this callback i remove child nod's drawables and add another ones. I check reference count before I remove them and it's 2 for some reason. My remove decreases it on 1 but it's not enough. Looks like viewer or something else keeps these drawables and therefore memleak happens.

I checked reference count of drawables after I add them to child's node and it's always 1 but when drawables come again to UpdateCallback it becomes 2.

The OSG's rendering backend retains a ref_ptr<> to the StateSet and
Drawables required for the current frame, but nothing beyond this.
It's not a memory leak at though, this is all cleaned up robustly.

If there is an actual leak in your program then perhaps you've created
a circular reference somewhere, could you have a child object, or
callback perhaps that holds a ref_ptr<> to a parent?

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
OmegaDoom
Newbie


Joined: 25 Jun 2018
Posts: 16

PostPosted: Thu Jul 12, 2018 4:21 pm    Post subject:
Reply with quote

No, why would I have a circular reference? And yes, I'm aware that circular references don't work with smart pointers. I will create a simple example which reproduces this issue.
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12094

PostPosted: Thu Jul 12, 2018 5:30 pm    Post subject:
How to track down memory leaks?
Reply with quote

On Thu, 12 Jul 2018 at 17:59, Igor Spiridonov <> wrote:
Quote:
No, why would I have a circular reference?

The OSG doesn't generally leak unless you do something pretty odd, the
codebase is pretty heavily tested now.

So we can only guess as to what might be wrong. Circular references
is one possibility. It might be something else odd that you are
doing. The small example that reproduces will be really helpful, as
there isn't else we can suggest at this point, so we just have to look
at code that illustrates the issue.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
OmegaDoom
Newbie


Joined: 25 Jun 2018
Posts: 16

PostPosted: Thu Jul 12, 2018 7:41 pm    Post subject:
Reply with quote

Here is simple project which reproduces this issue - RefCountTest

It's a visual studio project with qt and osg. Not sure you are using windows but the main code in scene.cpp. ref count checks inside "Scene::operator()(osg::Node* node, osg::NodeVisitor* nv)"

I expect both checks to return 1 but first one returns 2 as I explained earlier.

I suppose it's the cause of memleak. I use osg 3.2.
Back to top
View user's profile Send private message
Wojtek
User


Joined: 02 Nov 2011
Posts: 88

PostPosted: Thu Jul 12, 2018 10:50 pm    Post subject:
How to track down memory leaks?
Reply with quote

Hi, Igor,
I  got interested in this problem and checked your code by converting it to pure osgViewer. Here are my observations:


I believe you do have circular reference. Your class Scene is a callback. So RootNode points to callback but Scene callback points to RootNode. Hence circular ref.
However, this does not explain increased ref count of your geometries. But I believe this issue can be explained by by lazy clearing of render bins. RenderBins are not 

cleared after Draw but before next frame Draw. So after your Update, your geometry is Culled/Drawn and lands in RenderLeaves of RenderBin. This RenderBin is used to draw visible geometries but its not cleared after Draw. Its cleared later, ie on next Cull/Draw traversal when RenderLeaves container cleared before it gets filled again. So on next Update you will notice increased ref count because its also added to RenderLeaves container. But the next Cull/Draw will clear RenderLeaves and your geometry will be finally released. Here is your modified test applet code ported to vanilla osgViewer and modified to use observer_ptr instead of ref_ptr for RootNode. I have put breakpoint in MyGeometry Destructor to see the call stack and the call where the geometry is actually released and that way I found the explanation.


Cheers, hth,
Wojtek Lewandowski 



czw., 12 lip 2018 o 21:49 Igor Spiridonov < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> napisał(a):

Quote:
Here is simple project which reproduces this issue - RefCountTest (https://bitbucket.org/OmegaDoom/osgrefcounttest)

It's a visual studio project with qt and osg. Not sure you are using windows but the main code in scene.cpp. ref count checks inside "Scene::operator()(osg::Node* node, osg::NodeVisitor* nv)"

I expect both checks to return 1 but first one returns 2 as I explained earlier.

I suppose it's the cause of memleak. I use osg 3.2.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74334#74334





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
OmegaDoom
Newbie


Joined: 25 Jun 2018
Posts: 16

PostPosted: Fri Jul 13, 2018 4:25 pm    Post subject:
Reply with quote

Thank you Wojtek for your help.

But as I see it's not so simple. In my program some objects in Update function have ref count 2 but some(surprise, surprise) 1. And memory consumption growing steadily and constantly. The interesting objects those that use vbo. If I set all objects to use display lists then no visible memory leaks. I almost lost my hair and broke my head trying to figure out what's wrong with my program.

Looks like objects are disposed at different time and more objects disposed later. It's not pleasant to deal with such thing at all. You are not sure if it's a real memleak or just feature. I have object pools and they solve this issue but they complicate code. I'd like to get rid of them but I'm still not sure.

Robert, in my case memory consumption is not stabilizing, it grows until the app exits. I don't think there are bugs in my code. This program is simple and although refcount grows but it keeps under limit 50 all the time (usually it around 30-40). I watch memory in the task manager of the working set column.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Leaking memory on node removal Tini General 1 Fri May 25, 2018 6:48 pm View latest post
No new posts Leaking memory on node removal Tini General 0 Fri May 25, 2018 6:39 pm View latest post
No new posts Leaking memory on node removal Tini General 0 Fri May 25, 2018 6:30 pm View latest post
No new posts Leaking memory on node removal Tini General 0 Fri May 25, 2018 6:27 pm View latest post
No new posts How do I create a graphics context on... srinivas General 3 Tue Apr 24, 2018 11:40 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP