(svn r15330) -Fix [FS#2597]: leaking of Squirrel when using circular references (by enabling the GC).
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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());
|
||||
|
@@ -44,6 +44,11 @@ public:
|
||||
*/
|
||||
void GameLoop();
|
||||
|
||||
/**
|
||||
* Let the VM collect any garbage.
|
||||
*/
|
||||
void CollectGarbage();
|
||||
|
||||
/**
|
||||
* Get the storage of this AI.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user