From 1c30c8c801d2b4ecc6901069dcdfa8d0411aa1fd Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 3 Feb 2009 22:42:42 +0000 Subject: (svn r15330) -Fix [FS#2597]: leaking of Squirrel when using circular references (by enabling the GC). --- src/ai/ai_core.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/ai/ai_core.cpp') 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; } -- cgit v1.2.3-54-g00ecf