summaryrefslogtreecommitdiff
path: root/src/ai/ai_core.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-02-03 22:42:42 +0000
committerrubidium <rubidium@openttd.org>2009-02-03 22:42:42 +0000
commit1c30c8c801d2b4ecc6901069dcdfa8d0411aa1fd (patch)
tree4f0ff072e810fbda1bd6a01083ab7be1081bfdf3 /src/ai/ai_core.cpp
parent101f55e65cd43daea211b26b5fe5666968a507f4 (diff)
downloadopenttd-1c30c8c801d2b4ecc6901069dcdfa8d0411aa1fd.tar.xz
(svn r15330) -Fix [FS#2597]: leaking of Squirrel when using circular references (by enabling the GC).
Diffstat (limited to 'src/ai/ai_core.cpp')
-rw-r--r--src/ai/ai_core.cpp8
1 files changed, 8 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;
}