diff --git a/harbour/ChangeLog b/harbour/ChangeLog index cfe3759ff8..057f841056 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,14 @@ +2000-07-16 19:00 UTC+0100 Ryszard Glab + + *include/hbapi.h + *source/vm/hvm.c + *source/vm/memvars.c + * memvars table is deleted in two steps: first clear all + public and private variables (without the detached variables) + and next free space allocated for memvars table. These two steps + are separated with the garbage collector call so self + referencing variables will be deallocated properly. + 2000-07-16 17:40 UTC+0100 Ryszard Glab *include/hbhash.h diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 2ff6c64d9f..f336999812 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -439,7 +439,8 @@ extern void hb_codeblockCopy( PHB_ITEM pDest, PHB_ITEM pSource ); /* copy a extern HB_HANDLE hb_memvarValueNew( HB_ITEM_PTR pSource, BOOL bTrueMemvar ); /* create a new global value */ extern HB_VALUE_PTR * hb_memvarValueBaseAddress( void ); /* retrieve the base address of the values table */ extern void hb_memvarsInit( void ); /* initialize the memvar API system */ -extern void hb_memvarsRelease( void ); /* release the memvar API system */ +extern void hb_memvarsRelease( void ); /* clear all PUBLIC and PRIVATE variables */ +extern void hb_memvarsFree( void ); /* release the memvar API system */ extern void hb_memvarValueIncRef( HB_HANDLE hValue ); /* increase the reference count of a global value */ extern void hb_memvarValueDecRef( HB_HANDLE hValue ); /* decrease the reference count of a global value */ extern void hb_memvarSetValue( PHB_SYMB pMemvarSymb, HB_ITEM_PTR pItem ); /* copy an item into a symbol */ diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index ce80dd7970..cc8ec69245 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -356,11 +356,12 @@ void hb_vmQuit( void ) hb_stackPop(); hb_itemClear( &hb_stack.Return ); hb_arrayRelease( &s_aStatics ); - hb_memvarsRelease(); + hb_memvarsRelease(); /* clear all PUBLIC variables */ /* release all known garbage */ hb_gcCollectAll(); + hb_memvarsFree(); /* free memory allocated for memvars table */ hb_stackFree(); /* hb_dynsymLog(); */ hb_xexit(); diff --git a/harbour/source/vm/memvars.c b/harbour/source/vm/memvars.c index 88df31011f..fc2df2745d 100644 --- a/harbour/source/vm/memvars.c +++ b/harbour/source/vm/memvars.c @@ -96,27 +96,33 @@ void hb_memvarsInit( void ) s_privateStackCnt = s_privateStackBase = 0; } +/* clear all variables except the detached ones + * Should be called at application exit only +*/ void hb_memvarsRelease( void ) { ULONG ulCnt = s_globalLastFree; - HB_TRACE(HB_TR_DEBUG, ("hb_memvarsRelease()")); + HB_TRACE(HB_TR_DEBUG, ("hb_memvarsClear()")); if( s_globalTable ) { while( ulCnt ) { - if( s_globalTable[ ulCnt ].counter ) + if( s_globalTable[ ulCnt ].counter && s_globalTable[ ulCnt ].hPrevMemvar != ( HB_HANDLE )-1 ) { hb_itemClear( &s_globalTable[ ulCnt ].item ); s_globalTable[ ulCnt ].counter = 0; } --ulCnt; } - - hb_xfree( s_globalTable ); - s_globalTable = NULL; } +} + +void hb_memvarsFree( void ) +{ + if( s_globalTable ) + hb_xfree( s_globalTable ); if( s_privateStack ) hb_xfree( s_privateStack );