c++ - Can't delete dynamic object created in WxApp from OnExit() -
i'm trying understand how wxwidgets (3.0.1) app should designed, i'm missing i'm trying doesn't work.
at basic level, have wxapp, creates wxframe, gets displayed , works fine. decided add in logger object....
i made object member of wxapp:
class inilogwx : public wxapp { public: virtual bool oninit( ); virtual int onexit( ); private: clogstore * cl_logstore; };
and initialised in wxapp::oninit()
bool inilogwx::oninit( ) { mainframe * frame = new mainframe(_("log demo"), wxpoint(250, 250), wxsize(450, 340)); frame->show(true); settopwindow(frame); // create logger class clogstore * cl_logstore = new clogstore( ); return true; }
when application closed (closing mainframe) wxapp::onexit() fires, , thought i'd able clean memory here
int inilogwx::onexit( ) { delete cl_logstore; // unhandled exception here due invalid pointer return wxapp::onexit(); }
however, appear pointer no longer valid cannot use delete assigned memory.
the manual says "onexit called after destroying application windows , controls, before wxwidgets cleanup." figured own additional attributes still available me.
is not case?
the issue creating local variable happens match name used in class.
// create logger class clogstore * cl_logstore = new clogstore( );
the cl_logstore
here not same member variable cl_logstore
. local variable. not did call delete
on invalid pointer value, have memory leak.
Comments
Post a Comment