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/

Reply via email to