iTorque crash after 20 minutes.
by Javier Otaegui · in iTorque 2D · 01/20/2011 (8:07 am) · 10 replies
I am working on a big proyect, and after having a lot of memory problems i found that this function, that does not alocate anything, causes leak making the full game crash.
it only uses 2 global variables and one schedule. it does not uses graphics or anything (exept any graphic to set the behavior to).
i needs to be called from some place to start but once done and only 1 time, it will make the ipod crash in about 20 minutes (may be more if the ipod has more memory).
//the script name is as obvious isPause
function isPause::onLevelLoaded(%this)
{
%this.Check();
}
function isPause::Check(%this)
{
if ($cc $= "") {
$cc=0;
$Aux="";
}
else $cc++;
%aux="";
for (%i=0; %i<10; %i++)
{
%aux=appendWordToString(%aux, %i+$cc);
}
$Aux=%aux;
%this.schedule(500, "Check");
}
and a global function...
function appendWordToString(%string, %wordToAppend)
{
if(%string $= "")
%string = %wordToAppend;
else
%string = %string SPC %wordToAppend;
return %string;
}
(the function itself does some stupid stuff. as it only creates a string from 0 to 9 the first time, from 1 to 10 the second and so on, it was just done as a test, not expecting this to break the memory but it does it, so something is really wrong with the engine, in my case it leaks about 3k of memory each time it goes , or may be less if the timer of the schedule is not exact).
the project is severely overdued because of this, that was totaly unexpected so please see it as fast as posible.
I am running it in debug mode using the XCode linked to the ipod.
i did not tried emulating it or in the pc version as i do not intend to run it there.
on the other side i did not changed the engine and don't plan on doing so (unless the bug is fixed).
(this is using iTGB 1.4)
it only uses 2 global variables and one schedule. it does not uses graphics or anything (exept any graphic to set the behavior to).
i needs to be called from some place to start but once done and only 1 time, it will make the ipod crash in about 20 minutes (may be more if the ipod has more memory).
//the script name is as obvious isPause
function isPause::onLevelLoaded(%this)
{
%this.Check();
}
function isPause::Check(%this)
{
if ($cc $= "") {
$cc=0;
$Aux="";
}
else $cc++;
%aux="";
for (%i=0; %i<10; %i++)
{
%aux=appendWordToString(%aux, %i+$cc);
}
$Aux=%aux;
%this.schedule(500, "Check");
}
and a global function...
function appendWordToString(%string, %wordToAppend)
{
if(%string $= "")
%string = %wordToAppend;
else
%string = %string SPC %wordToAppend;
return %string;
}
(the function itself does some stupid stuff. as it only creates a string from 0 to 9 the first time, from 1 to 10 the second and so on, it was just done as a test, not expecting this to break the memory but it does it, so something is really wrong with the engine, in my case it leaks about 3k of memory each time it goes , or may be less if the timer of the schedule is not exact).
the project is severely overdued because of this, that was totaly unexpected so please see it as fast as posible.
I am running it in debug mode using the XCode linked to the ipod.
i did not tried emulating it or in the pc version as i do not intend to run it there.
on the other side i did not changed the engine and don't plan on doing so (unless the bug is fixed).
(this is using iTGB 1.4)
#2
and if i do so, do the echo part works in release (if not i will be unable to see if it works or not).
but I need to check it in debug to be able to fix some bugs that came in after playing it a lot of time (for now its memory and its preventing me to see any more).
Did you run the same routine i set on mac and ipod?
01/24/2011 (5:35 am)
For some reason i was not able to use release mode on my proyect yet but...how will release be any different?and if i do so, do the echo part works in release (if not i will be unable to see if it works or not).
but I need to check it in debug to be able to fix some bugs that came in after playing it a lot of time (for now its memory and its preventing me to see any more).
Did you run the same routine i set on mac and ipod?
#3
its acting as if every new variable is never deleted (even local variables when the function ends).
so every time a new one is found instead of using the same it allocates more and more memory for it.
and the only problem of that is that when the function ends it just mark that variables as deleted but never use them again, and never really free them either.
(I intercepted the 3 functions malloc, free, and realoc, and made an array (of fixed length and 64k), for now the memory crash before its fully loaded. but it allocates almos 1 GB of memory and then it crashes.
i did not found any other malloc or free in the code.
but, if there should be any other may be thats the problem.
please check this ASAP as a 5 month project is on the edge of its limit date and cannot be released with this problem.
01/24/2011 (5:51 am)
Can somebody at least tell me wich .c files and functions should be responsable for this?its acting as if every new variable is never deleted (even local variables when the function ends).
so every time a new one is found instead of using the same it allocates more and more memory for it.
and the only problem of that is that when the function ends it just mark that variables as deleted but never use them again, and never really free them either.
(I intercepted the 3 functions malloc, free, and realoc, and made an array (of fixed length and 64k), for now the memory crash before its fully loaded. but it allocates almos 1 GB of memory and then it crashes.
i did not found any other malloc or free in the code.
but, if there should be any other may be thats the problem.
please check this ASAP as a 5 month project is on the edge of its limit date and cannot be released with this problem.
#4
explained more or less the use of the PUAP_SCRIPT_CHANGE define
with that enabled, seems to leak less even so i made some test to check how much memory was being loose.
both funcions were run for 10 minutes and the amount of memory loose was this in each case 4336 bytes loose in 167 not free pointers in the on that only has the schedule
function isPause::Check(%this)
{
%this.schedule(9876, "Check");
}
as you see this function does "nothing" except to call itself every almost 10 seconds. its really plain and simple so that means that the core is not working.
even so this is not the only that looses memory as just setting variables make it loose more as reveled here where 21801 bytes loose in 167 not free pointers in this version
function isPause::Check(%this)
{
if ($cc $= "") {
$cc=0;
$Aux="";
}
else $cc++;
%aux="";
for (%j=0; %j<10; %j++) {
for (%i=0; %i<10; %i++)
{
%aux2=%i+$cc;
if(%aux $= "")
%aux = %aux2;
else
%aux = %aux SPC %aux2;
}
$Aux=%aux;
}
%this.schedule(9876, "Check");
}
and it does not matter really if there are 20 k o 400 byes.
as this game is supposed to be able to run for hours.
(and just doing this little function make it loose a lot).
i am not sure if its the schedule the problem.
but as i asked before is there any other define i may try?
or any idea on how to correct this?
(I need schedules, if someone say do not use is the same as saying it cant be done)
01/24/2011 (6:37 am)
The previous thread about "Serious Memory leaks on objects collisions system"explained more or less the use of the PUAP_SCRIPT_CHANGE define
with that enabled, seems to leak less even so i made some test to check how much memory was being loose.
both funcions were run for 10 minutes and the amount of memory loose was this in each case 4336 bytes loose in 167 not free pointers in the on that only has the schedule
function isPause::Check(%this)
{
%this.schedule(9876, "Check");
}
as you see this function does "nothing" except to call itself every almost 10 seconds. its really plain and simple so that means that the core is not working.
even so this is not the only that looses memory as just setting variables make it loose more as reveled here where 21801 bytes loose in 167 not free pointers in this version
function isPause::Check(%this)
{
if ($cc $= "") {
$cc=0;
$Aux="";
}
else $cc++;
%aux="";
for (%j=0; %j<10; %j++) {
for (%i=0; %i<10; %i++)
{
%aux2=%i+$cc;
if(%aux $= "")
%aux = %aux2;
else
%aux = %aux SPC %aux2;
}
$Aux=%aux;
}
%this.schedule(9876, "Check");
}
and it does not matter really if there are 20 k o 400 byes.
as this game is supposed to be able to run for hours.
(and just doing this little function make it loose a lot).
i am not sure if its the schedule the problem.
but as i asked before is there any other define i may try?
or any idea on how to correct this?
(I need schedules, if someone say do not use is the same as saying it cant be done)
#5
And after being able to do it it crash in the exactly same way as before.
NO DIFERENCE
01/25/2011 (5:52 am)
By the way i was working on making it into release mode to check.And after being able to do it it crash in the exactly same way as before.
NO DIFERENCE
#6
02/02/2011 (12:06 pm)
after at least a week there is no answer to this problem?
#7
Have you attempted to call the global version of schedule, rather than the class method off isPause? Same results?
02/02/2011 (1:59 pm)
@Javier - Are you saying the following, alone, leaks memory?function isPause::Check(%this)
{
%this.schedule(9876, "Check");
}Have you attempted to call the global version of schedule, rather than the class method off isPause? Same results?
#8
And yes that and the other function above both leak memory as i said already.
It will make sense if it allocates all that variables once, but, it makes no sense that it allocates all them (and do not delete them) all the time and each time it gets inside the function.
because going on with the real script and not just this example it looses memory in the same way.
but even so, it is using iTGB 1.4 in iPod compiling in GCC 4.2 and OS for iPhone 3.2.
it Can't be fully tested on window because some functions do not exist (and it uses other memory manager on window).
02/03/2011 (5:44 am)
yes, its exactly the same but the real problem, even if the schedule loose data is that the other loose even more data, and by that i mean the part that just equal variables.And yes that and the other function above both leak memory as i said already.
It will make sense if it allocates all that variables once, but, it makes no sense that it allocates all them (and do not delete them) all the time and each time it gets inside the function.
because going on with the real script and not just this example it looses memory in the same way.
but even so, it is using iTGB 1.4 in iPod compiling in GCC 4.2 and OS for iPhone 3.2.
it Can't be fully tested on window because some functions do not exist (and it uses other memory manager on window).
#9
02/05/2011 (7:45 am)
Will it crash that quickly if you don't have Instruments hooked up to it? I mentioned in some other post somewhere that hooking up the memory monitor from Instruments was causing things to leak memory and crash incredibly fast.
#10
and to "check" how much memory it uses i just intercepted the malloc, free and remalloc that uses 64k of static memory (that way is impposible for my own monitoring code to leak).
So in other words the leak is entirely because of torque.
02/07/2011 (5:20 am)
I do no have any monitoring device hooked into it.and to "check" how much memory it uses i just intercepted the malloc, free and remalloc that uses 64k of static memory (that way is impposible for my own monitoring code to leak).
So in other words the leak is entirely because of torque.
Torque 3D Owner Alistair Lowe3