예제 #1
0
파일: sqstate.cpp 프로젝트: elleryq/madedit
SQInteger SQSharedState::CollectGarbage(SQVM *vm)
{
	SQInteger n=0;
	SQCollectable *tchain=NULL;

	RunMark(vm,&tchain);

	SQCollectable *t = _gc_chain;
	SQCollectable *nx = NULL;
	while(t) {
		t->_uiRef++;
		t->Finalize();
		nx = t->_next;
		if(--t->_uiRef == 0)
			t->Release();
		t = nx;
		n++;
	}

	t = tchain;
	while(t) {
		t->UnMark();
		t = t->_next;
	}
	_gc_chain = tchain;
	
	return n;
}
예제 #2
0
SQSharedState::~SQSharedState()
{
    if(_releasehook) { _releasehook(_foreignptr,0); _releasehook = NULL; }
    _constructoridx.Null();
    _table(_registry)->Finalize();
    _table(_consts)->Finalize();
    _table(_metamethodsmap)->Finalize();
    _registry.Null();
    _consts.Null();
    _metamethodsmap.Null();
    while(!_systemstrings->empty()) {
        _systemstrings->back().Null();
        _systemstrings->pop_back();
    }
    _thread(_root_vm)->Finalize();
    _root_vm.Null();
    _table_default_delegate.Null();
    _array_default_delegate.Null();
    _string_default_delegate.Null();
    _number_default_delegate.Null();
    _closure_default_delegate.Null();
    _generator_default_delegate.Null();
    _thread_default_delegate.Null();
    _class_default_delegate.Null();
    _instance_default_delegate.Null();
    _weakref_default_delegate.Null();
    _refs_table.Finalize();
#ifndef NO_GARBAGE_COLLECTOR
    SQCollectable *t = _gc_chain;
    SQCollectable *nx = NULL;
    if(t) {
        t->_uiRef++;
        while(t) {
            t->Finalize();
            nx = t->_next;
            if(nx) nx->_uiRef++;
            if(--t->_uiRef == 0)
                t->Release();
            t = nx;
        }
    }
    assert(_gc_chain==NULL); //just to proove a theory
    while(_gc_chain){
        _gc_chain->_uiRef++;
        _gc_chain->Release();
    }
#endif

    sq_delete(_types,SQObjectPtrVec);
    sq_delete(_systemstrings,SQObjectPtrVec);
    sq_delete(_metamethods,SQObjectPtrVec);
    sq_delete(_stringtable,SQStringTable);
    if(_scratchpad)SQ_FREE(_scratchpad,_scratchpadsize);
}
예제 #3
0
SQInteger SQSharedState::CollectGarbage(SQVM *vm)
{
	SQInteger n=0;
	SQCollectable *tchain=NULL;
	SQVM *vms = _thread(_root_vm);
	
	vms->Mark(&tchain);
	SQInteger x = _table(_thread(_root_vm)->_roottable)->CountUsed();
	_refs_table.Mark(&tchain);
	MarkObject(_registry,&tchain);
	MarkObject(_consts,&tchain);
	MarkObject(_metamethodsmap,&tchain);
	MarkObject(_table_default_delegate,&tchain);
	MarkObject(_array_default_delegate,&tchain);
	MarkObject(_string_default_delegate,&tchain);
	MarkObject(_number_default_delegate,&tchain);
	MarkObject(_generator_default_delegate,&tchain);
	MarkObject(_thread_default_delegate,&tchain);
	MarkObject(_closure_default_delegate,&tchain);
	MarkObject(_class_default_delegate,&tchain);
	MarkObject(_instance_default_delegate,&tchain);
	MarkObject(_weakref_default_delegate,&tchain);
	
	SQCollectable *t = _gc_chain;
	SQCollectable *nx = NULL;
	while(t) {
		t->_uiRef++;
		t->Finalize();
		nx = t->_next;
		if(--t->_uiRef == 0)
			t->Release();
		t = nx;
		n++;
	}

	t = tchain;
	while(t) {
		t->UnMark();
		t = t->_next;
	}
	_gc_chain = tchain;
	SQInteger z = _table(_thread(_root_vm)->_roottable)->CountUsed();
	assert(z == x);
	return n;
}