# HG changeset patch # User Jaroslav Hajek # Date 1260789113 -3600 # Node ID 692ab4eaf9659d7c1baaadb3369bc7dd9905729c # Parent e352f8366b02f1545afafc551b5ea148c91f4f2f clean up top-level variables when exiting Octave diff -r e352f8366b02 -r 692ab4eaf965 src/ChangeLog --- a/src/ChangeLog Sun Dec 13 22:32:47 2009 -0800 +++ b/src/ChangeLog Mon Dec 14 12:11:53 2009 +0100 @@ -1,3 +1,9 @@ +2009-12-14 Jaroslav Hajek + + * symtab.cc (symbol_table::cleanup): New static method. + * symtab.h: Declare it. + * toplev.cc (clean_up_and_exit): Call it here. + 2009-12-12 Shai Ayal * DLD-FUNCTIONS/fltk_backend.cc (plot_window::toggle_grid, diff -r e352f8366b02 -r 692ab4eaf965 src/symtab.cc --- a/src/symtab.cc Sun Dec 13 22:32:47 2009 -0800 +++ b/src/symtab.cc Mon Dec 14 12:11:53 2009 +0100 @@ -1331,6 +1331,39 @@ } } +void symbol_table::cleanup (void) +{ + // Clear variables in top scope. + all_instances[xtop_scope]->clear_all (); + + // Clear function table. This is a hard clear, ignoring mlocked functions. + fcn_table.clear (); + + // Clear variables in global scope. + // FIXME: are there any? + all_instances[xglobal_scope]->clear_all (); + + // Clear global variables. + global_table.clear (); + + // Delete all possibly remaining scopes. + for (all_instances_iterator iter = all_instances.begin (); + iter != all_instances.end (); iter++) + { + scope_id scope = iter->first; + if (scope != xglobal_scope && scope != xtop_scope) + scope_id_cache::free (scope); + + // First zero the table entry to avoid possible duplicate delete. + symbol_table *inst = iter->second; + iter->second = 0; + + // Now delete the scope. Note that there may be side effects, such as + // deleting other scopes. + delete inst; + } +} + DEFUN (ignore_function_time_stamp, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} ignore_function_time_stamp ()\n\ diff -r e352f8366b02 -r 692ab4eaf965 src/symtab.h --- a/src/symtab.h Sun Dec 13 22:32:47 2009 -0800 +++ b/src/symtab.h Mon Dec 14 12:11:53 2009 +0100 @@ -1828,6 +1828,8 @@ inst->curr_fcn = curr_fcn; } + static void cleanup (void); + private: typedef std::map::const_iterator table_const_iterator; diff -r e352f8366b02 -r 692ab4eaf965 src/toplev.cc --- a/src/toplev.cc Sun Dec 13 22:32:47 2009 -0800 +++ b/src/toplev.cc Mon Dec 14 12:11:53 2009 +0100 @@ -673,6 +673,9 @@ { do_octave_atexit (); + // Clean up symbol table. + SAFE_CALL (symbol_table::cleanup, ()); + SAFE_CALL (sysdep_cleanup, ()) if (octave_exit)