diff --git a/HISTORY b/HISTORY index b49748c..09d4dc2 100755 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,5 @@ Jan. 12 2016 +Improved sub routine by unreference objects which were out of scope Fixed a routine evaluation bug when it's stored in a variable Fixed a disposing issue with collection iterators Fixed some memory leak with lambda diff --git a/core/my_basic.c b/core/my_basic.c index 31fcaf2..8a15998 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -1459,6 +1459,7 @@ static int _destroy_object_not_compile_time(void* data, void* extra); static int _destroy_object_capsule_only(void* data, void* extra); static int _destroy_object_capsule_only_with_extra(void* data, void* extra); static int _do_nothing_on_object(void* data, void* extra); +static int _lose_object(void* data, void* extra); static int _remove_source_object(void* data, void* extra); static int _destroy_memory(void* data, void* extra); static int _compare_numbers(const _object_t* first, const _object_t* second); @@ -6723,9 +6724,10 @@ void _out_of_scope(mb_interpreter_t* s, _running_context_t* running) { _ls_destroy(running->refered_lambdas); running->refered_lambdas = 0; } -#else /* MB_ENABLE_LAMBDA */ - mb_unrefvar(running); #endif /* MB_ENABLE_LAMBDA */ + + if(running->var_dict) + _ht_foreach(running->var_dict, _lose_object); } _running_context_t* _find_scope(mb_interpreter_t* s, _running_context_t* p) { @@ -7234,6 +7236,39 @@ int _do_nothing_on_object(void* data, void* extra) { return result; } +int _lose_object(void* data, void* extra) { + /* Lose an object of of scope */ + int result = _OP_RESULT_NORMAL; + _object_t* obj = 0; + bool_t make_nil = true; + + mb_assert(data && extra); + + obj = (_object_t*)data; + switch(obj->type) { + case _DT_VAR: + _lose_object(obj->data.variable->data, extra); + make_nil = false; + + break; + _UNREF_USERTYPE_REF(obj) + _UNREF_ARRAY(obj) + _UNREF_COLL(obj) + _UNREF_CLASS(obj) + _UNREF_ROUTINE(obj) + default: + make_nil = false; + + break; + } + + if(make_nil) { + _MAKE_NIL(obj); + } + + return result; +} + int _remove_source_object(void* data, void* extra) { /* Remove an object referenced to source code */ int result = _OP_RESULT_DEL_NODE; diff --git a/output/my_basic.exe b/output/my_basic.exe index f581d91..458ffb2 100755 Binary files a/output/my_basic.exe and b/output/my_basic.exe differ