Page 1 of 1
Memory leaks
Posted: 18 Nov 2008 21:17
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;
}
}
Re: Memory leaks
Posted: 22 Nov 2008 17:55
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.
Re: Memory leaks
Posted: 23 Nov 2008 10:25
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?
Re: Memory leaks
Posted: 04 Jan 2009 15:05
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?