diff options
author | rubidium <rubidium@openttd.org> | 2009-02-03 22:42:42 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-02-03 22:42:42 +0000 |
commit | 1c30c8c801d2b4ecc6901069dcdfa8d0411aa1fd (patch) | |
tree | 4f0ff072e810fbda1bd6a01083ab7be1081bfdf3 /src/ai | |
parent | 101f55e65cd43daea211b26b5fe5666968a507f4 (diff) | |
download | openttd-1c30c8c801d2b4ecc6901069dcdfa8d0411aa1fd.tar.xz |
(svn r15330) -Fix [FS#2597]: leaking of Squirrel when using circular references (by enabling the GC).
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/ai_core.cpp | 8 | ||||
-rw-r--r-- | src/ai/ai_instance.cpp | 5 | ||||
-rw-r--r-- | src/ai/ai_instance.hpp | 5 |
3 files changed, 18 insertions, 0 deletions
diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp index e9e2a5bd2..e49a7dd4b 100644 --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -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; } diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp index 26d55481b..37529eeab 100644 --- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -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()); diff --git a/src/ai/ai_instance.hpp b/src/ai/ai_instance.hpp index 688b3c133..9c1aaca59 100644 --- a/src/ai/ai_instance.hpp +++ b/src/ai/ai_instance.hpp @@ -45,6 +45,11 @@ public: void GameLoop(); /** + * Let the VM collect any garbage. + */ + void CollectGarbage(); + + /** * Get the storage of this AI. */ static class AIStorage *GetStorage(); |