(svn r15330) -Fix [FS#2597]: leaking of Squirrel when using circular references (by enabling the GC).

This commit is contained in:
rubidium
2009-02-03 22:42:42 +00:00
parent 101f55e65c
commit 1c30c8c801
10 changed files with 44 additions and 17 deletions

View File

@@ -3,6 +3,7 @@
/** @file ai_core.cpp Implementation of AI. */
#include "../stdafx.h"
#include "../core/bitmath_func.hpp"
#include "../company_base.h"
#include "../company_func.h"
#include "../debug.h"
@@ -68,6 +69,13 @@
}
}
/* Occasionally collect garbage; every 255 ticks do one company.
* Effectively collecting garbage once every two months per AI. */
if ((AI::frame_counter & 255) == 0) {
CompanyID cid = (CompanyID)GB(AI::frame_counter, 8, 4);
if (IsValidCompanyID(cid) && !IsHumanCompany(cid)) GetCompany(cid)->ai_instance->CollectGarbage();
}
_current_company = OWNER_NONE;
}

View File

@@ -296,6 +296,11 @@ void AIInstance::GameLoop()
}
}
void AIInstance::CollectGarbage()
{
if (this->is_started && !this->is_dead) this->engine->CollectGarbage();
}
/* static */ void AIInstance::DoCommandReturn(AIInstance *instance)
{
instance->engine->InsertResult(AIObject::GetLastCommandRes());

View File

@@ -44,6 +44,11 @@ public:
*/
void GameLoop();
/**
* Let the VM collect any garbage.
*/
void CollectGarbage();
/**
* Get the storage of this AI.
*/