[osg-users] found memory leak in OSG 3.0.1
Gianluca Natale
natale at europe.altair.com
Fri Jan 20 01:13:26 PST 2017
Hi Robert, thanks for your reply.
This is what I do in my application:
1) create my own Qt widget (and get its window handle, HWND);
2) allocate an osgViewer::Viewer;
3) allocate Traits and set requirements (new osg::GraphicsContext::Traits(); )
4) set the window handle gotten at point 1 in the Traits (traits->inheritedWindowData = new WindowData((HWND)window); )
5) create a graphic context using such Traits (osg::GraphicsContext::createGraphicsContext(traits.get()); )
internally that function calls this:
5.1) osg::GraphicsContext::createGraphicsContext(traits.get());
that in its turn calls this:
5.1.1) GraphicsWindowWin32::init(); // SO FAR, NO MEMORY HAS BEEN ALLOCATED YET (OR JUST UNNOTICEABLE AMOUNT)
that internally makes this call:
GraphicsWindowWin32::setWindow( HWND handle ) // handle is the one I passed at step 4
that in its turn performs this 2 calls:
5.1.1.1) GraphicsWindowWin32::setPixelFormat(); // THIS ALLOCATES ABOUT 1 MB
5.1.1.2) _hglrc = createContextImplementation(); // THIS ALLOCATES ABOUT 1.5 MB
NO MORE MEMORY IS ALLOCATED FROM NOW ON
6) set the graphics context for my viewer (p_viewer->getCamera()->setGraphicsContext(p_graphicsContext); ) // where p_ graphicsContext is that created at step 5, and stored in my class as a reference pointer
I DO NOT DO ANYTHING ELSE NOW, BUT SOON DESTROY WHAT I'VE ALLOCATED, IN REVERSE ORDER (BY DESTRUCTING MY OWN CLASS, WHERE I HAD PERFORMED THE CREATION OF EVERYTHING). THAT IS TO SAY,
I FORCE THE DESTRUCTION OF MY OWN CLASS, AND IN THE DESTRUCTOR:
7) release the graphic context (p_graphicsContext->releaseContext(); )
8) close the graphics context (p_graphicsContext->close(true);) // MEMORY IS DECREASED BY 1.5 MB
9) delete the viewer.
10) destruction of the graphics context happens automatically when my class is destroyed, since I had stored 'p_graphicsContext' as a reference pointer.
I put a breakpoint and verified that the following destructor is called:
10.1) GraphicsWindowWin32::~GraphicsWindowWin32();
This internally performs 2 calls:
10.1.1) close(); // NO MEMORY DEALLOCATED, I GUESS BECAUSE I HAD ALREADY CALLED THIS AT STEP 8
10.1.2) destroyWindow();// NO MEMORY DEALLOCATED
That's it.
Do you feel that I made something wrong, Robert? Or is there something else that I have to call to force some deallocation?
As I mentioned here above, in the whole process the memory is allocated in 2 points, but it looks like only second allocation is removed.
I've also investigated a bit inside the function at step 5.1.1.1).
This seems to be the call that allocates an amount of memory that it is not released at the end of the process:
Win32WindowingSystem::getInterface()->getSampleOpenGLContext(openGLContext, _hdc, _screenOriginX, _screenOriginY);
Any idea about that?
Thank you very much for your support, Robert.
Gianluca Natale
-----Original Message-----
From: osg-users [mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Robert Osfield
Sent: Thursday, January 19, 2017 6:53 PM
To: OpenSceneGraph Users <osg-users at lists.openscenegraph.org>
Subject: Re: [osg-users] found memory leak in OSG 3.0.1
Hi Gianluca,
How you are measuring the memory usage? It could simply be that the memory tracking isn't properly handling deallocations.
As a general note, close will just close the graphics context, it won't delete the osg::GraphicsWindowWin32. Try testing the creation of a viewer within a well defined scope and then see what memory has been deallocated or not on leaving the scope where all the viewer related objects should be cleaned up.
Robert.
On 19 January 2017 at 17:02, Gianluca Natale <natale at europe.altair.com> wrote:
> Hi all,
>
> In my application I’m using OSG 3.0.1 (I do know it is old, but I do
> not have the time now to move to a newer version).
>
> I think I have a memory leak, and I don’t know if it’s my fault or a
> bug in OSG.
>
> Using the task manager (on Win 8.1 Pro), I see this.
>
>
>
> When I call:
>
>
>
> GraphicsContext* GraphicsContext::createGraphicsContext(Traits*
> traits);
>
>
>
> memory allocated in my application increases of about 2.5 MB.
>
>
>
> Then, when I call:
>
>
>
> GraphicsContext::close(bool callCloseImplementation); // I pass true
> to this function
>
>
>
> memory allocated in my application decreases of about 1.5 MB.
>
> So, there is always about 1 MB that is not deallocated.
>
>
>
> I tried to investigate a bit, and noticed that the problem seems to
> happen inside this function:
>
>
>
> bool GraphicsWindowWin32::setWindow( HWND handle ).
>
>
>
> Specifically, there are 2 calls in that function where memory is allocated:
>
>
>
> 1) bool GraphicsWindowWin32::setPixelFormat(); // increases about 1 MB
>
> 2) HGLRC GraphicsWindowWin32::createContextImplementation(); //
> increases about 1.5 MB
>
>
>
> So, it looks like the memory allocated at point 1 is never released.
>
> Is there anything I have to call, when I want to destroy a graphic
> context, other than close()?
>
> Or, if you do know that it is a memory leak, has it been fixed in a
> newer version of OSG?
>
>
> Thanks,
>
> Gianluca Natale
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.
> org
>
_______________________________________________
osg-users mailing list
osg-users at lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
More information about the osg-users
mailing list