I read this in the Delta3D docs and never understood why. 

 

Delta3D mentions that:

Destructors for subclasses of dtCore::Base must have protected destructors.  Otherwise use of RefPtrs will cause some serious problems if the objects are allocated on the stack.

 

So why is this?

 

Any although this might have fixed some problems, I am still having the same crashes on an Invalid Address specified to RtlFreeHeap.  When I comment out my 2 lines for my EventHandler creation, I do not get these errors…

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jolley, Thomas P
Sent: Monday, August 21, 2006 12:55 PM
To: osg users
Subject: [Norton AntiSpam] RE: [osg-users] Event handler memory leak...

 

Hi Jeff,

 

You need to make sure any class derived from osg::Referenced has a destructor that is _not_ public.  You don't want a default destructor.

 


From: Don Burns [mailto:[EMAIL PROTECTED]
Sent: Monday, August 21, 2006 2:46 PM
To: osg users
Subject: Re: [osg-users] Event handler memory leak...

What is this:

EventHandler* pEventHandler = new EventHandler();

(from your original message)

-don

On 8/21/06, Jeff Kershner <[EMAIL PROTECTED]> wrote:

Nothing is dynamically allocated in my test app and so I am not freeing or deleting anything.

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Don Burns
Sent: Monday, August 21, 2006 12:09 PM


To: osg users
Subject: Re: [osg-users] Event handler memory leak...

 

Are you freeing something that was already being managed by a ref_ptr?

On 8/21/06, Jeff Kershner <[EMAIL PROTECTED]> wrote:

Thanks for the reply:

 

So now I declared my derived event handler class like this:

 

osg::ref_ptr<osgGA::GUIEventHandler> eh(new EventHandler());

m_Viewer.getEventHandlerList().push_front(eh);

 

But I am getting a crash in the msvcr71d.dll in free.c.  I believe the error I am getting is this:

 

`scalar deleting destructor'() + 0x42

`scalar deleting destructor'() + 0x5b

 

So this is either MSVC++ 7.1 telling me that it is breaking on what it thinks to be a memory leak, or it is actually trying to free something that has already been freed.  Since this crash only happens when I run with the debugger, I am leaning towards the first…

 

Any ideas?

 

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Don Burns
Sent: Friday, August 18, 2006 4:54 PM
To: osg users
Subject: Re: [osg-users] Event handler memory leak...

 

Hi Jeff,

Note that the definition for EventHandlerList is:

        typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlerList;

So, when you call

m_Viewer.getEventHandlerList().push_front(pEventHandler);


The address stored in pEventHandler is then managed by a ref_ptr, the reference count is incremented.  When the Viewer's eventHandlerList goes out of scope, the reference on the address will be decremented, and if the result is a reference count of 0, it will be deleted.  You should not delete it in your own code.

BTW, some compilers and profiling tools don't handle reference pointers well and may give you faulty information about memory leaks.

-don

On 8/16/06, Jeff Kershner <[EMAIL PROTECTED]> wrote:

I have an event handler class like this:

 

class EventHandler : public osgGA::GUIEventHandler

{

public:

            virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);

};

 

The handle function just calls the base class' handle function…

 

This is how it is implemented:

EventHandler* pEventHandler = new EventHandler();

m_Viewer.getEventHandlerList().push_front(pEventHandler);

 

 

When my application exits, I get a memory leak that is caused by this EventHandler.  Do I need to delete this EventHandler pointer?

 

It feels weird to delete a pointer that I am handing to another system…

 

Finally, as a side note, does the EventHandler class that I create need to have a virtual destructor explicitly written?

 

Thanks,

/jk


_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

 


_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

 


_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

 

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to