Memory leaks

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
svetovoi
Engineer
Engineer
Posts: 87
Joined: 12 Oct 2007 14:07

Memory leaks

Post by svetovoi »

I've noticed that objects circularly refer to each other provoke memory leaks. Memory not cleaned, even after abandoning the game and returning to the main menu.
Seems reason in Squirrel garbage collector.

Very good seen with following AI Start function:

Code: Select all

function Start()
{
	while (true) {
		local object1 = {};
		local object2 = {};
		object1.pointer <- object2;
		object2.pointer <- object1;
	}
}
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Memory leaks

Post by TrueBrain »

ac84 wrote:I've noticed that objects circularly refer to each other provoke memory leaks. Memory not cleaned, even after abandoning the game and returning to the main menu.
Seems reason in Squirrel garbage collector.

Very good seen with following AI Start function:

Code: Select all

function Start()
{
	while (true) {
		local object1 = {};
		local object2 = {};
		object1.pointer <- object2;
		object2.pointer <- object1;
	}
}
Most language where you create a circle reference don't free their memory correctly; doubtful that will ever be fixed.
The only thing necessary for the triumph of evil is for good men to do nothing.
svetovoi
Engineer
Engineer
Posts: 87
Joined: 12 Oct 2007 14:07

Re: Memory leaks

Post by svetovoi »

TrueBrain wrote:Most language where you create a circle reference don't free their memory correctly
And Squirrel replacement language (you are going to replace Squirrel, right) too?
TrueBrain wrote:doubtful that will ever be fixed
So, AI writer is responding (mean no circle reference at all) for memory leaks?
FloppyCat
Engineer
Engineer
Posts: 1
Joined: 04 Jan 2009 14:49

Re: Memory leaks

Post by FloppyCat »

Quoting Squirrel documentation:
Squirrel uses reference counting (RC) as primary system for memory management; however, the virtual
machine (VM) has an auxiliary mark and sweep garbage collector that can be invoked on demand.
...
The default configuration consists in RC plus a mark and sweep garbage collector. The host program
can call the function sq_collectgarbage() and perform a garbage collection cycle during the program
execution. The garbage collector isn’t invoked by the VM and has to be explicitly called by the host
program.
There is also Squirrel function collectgarbage(), but it doesn't work in AI code ("the index 'collectgarbage' does not exists").
Cleaning up circle references manually is not an option, as AI does not have a chance to do cleanup when it is terminated. Not using circle references is extremely incovenient and might be difficult to avoid.
Why not to use Squirrel garbage collector?
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest