HI Thibault,

I'm not happy with the solution you've come up with as there is no
formalised destruction order - how can we be 100% sure that the steam
buffer won't be deleted before the stream?  With this uncertainty I'm
not going to merge as a theoretical leak of 60 bytes is far less (the
OS will clean up this memory on closing the app) of a problem that a
possible crash.

Robert.

On Tue, Aug 5, 2008 at 2:30 PM, Thibault Genessay <[EMAIL PROTECTED]> wrote:
> Hi Robert,
>
> After upgrading to the latest OSG recently, I spotted a memory leak.
> After some investigations, I found that the guilty was the revision
> 8400, which introduced a custom null stream as a replacement for
> /dev/null. The code instantiates a custom streambuf (line 99: new
> NullStreamBuffer()) and binds it to an ostream. This works well but
> the NullStreamBuffer is never freed, resulting in a 60 bytes memory
> leak when the program terminates.
>
> The attached file fixes this by creating the custom streambuf on the
> stack and passing a pointer to it to the ostream. I have tried it on
> Windows XP SP3 + OSG rev 8647.
>
> Another solution - which I have tried and works as well - would be
> deriving the NullStreamBuffer from osg::Referenced and keeping a
> static ref_ptr to it. It seems more complicated for no apparent
> benefits so I went the stack route.
>
> The question of why this memory leak is not reported when I run
> "osgviewer cow.osg" remains a mystery to me - I suspect this is a
> "feature" of Microsoft's debugging CRT. It would only show up in my
> application as well as in a minimal sample using wxWidgets and OSG.
> However, assuming that the ostream does not own the streambuf you pass
> it (I could not find any evidence that it does) there is clearly a
> leak.(*)
>
> Regards
>
> Thibault
>
> (*) Somewhere on the page
> http://www.slac.stanford.edu/comp/unix/gnu-info/iostream_3.html I have
> found
> "If you give the ostream a streambuf explicitly, using this
> constructor, the sb is not destroyed (or deleted or closed) when the
> ostream is destroyed."
>
> _______________________________________________
> osg-submissions mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
>
>
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to