Memory Leak

Posted By: hanselkoh

Memory Leak - 11/10/11 19:59

Hi Folks,

I kept have memory leaks despite having ptr_remove().

I am not sure if I am checking the right way, but what I did was I ran the game while looking at the resources used in task manger and it just kept increasing.

here is the short code I wrote.

while(1)
{
ENTITY* enemy = ent_create("unitGolem.wmb", vector(startX,laneY[5],0), putGolem);

ptr_remove(enemy);
wait(10);
}

Any clue on what I did wrongly? Thanks for looking.
Posted By: Stromausfall

Re: Memory Leak - 11/10/11 20:52

i used the following code and couldn't reproduce the problem :

Code:
void putGolem()
{
	while(1)
	{
		wait(1);
	}
}

int main()
{
	level_load(NULL);
	wait(1);
	
	while(1)
	{
		ENTITY* enemy = ent_create(CUBE_MDL, vector(1,2,3), putGolem);
	
		ptr_remove(enemy);
		wait(1);
	}
}



I guess the memory leak is most likely hidden somewhere else ...
Posted By: hanselkoh

Re: Memory Leak - 11/11/11 03:22

Thanks Stromausfall, I tried again with a .mdl file instead of .wmb, it seems to be more controlled. But I am still unsure if it's still leaking. How or what is the right way to check for memory leaks?
Posted By: EvilSOB

Re: Memory Leak - 11/11/11 06:40

Entities are a known memory leak, IN CERTAIN CONDITIONS.
I have spent MUCH time discussing it with JCL, for years now...

BTW, 'memory leak' is not the correct term to use.
In normal usage the term 'memory leak' means memory that has 'escaped' the applications control.
In THIS case, acknex still has control over the memory, just your script no longer has...
But for the sake of simplicity, we will keep calling it a 'leak' for now...


Your leak may be coming from several sources. If you test with the example code
that Stromausfall posted above, it will take a LONG time to get any noticable memory loss.
Explaination of the 'certain conditions' can be found in point #1 and #3 below.
So read on...

1> You really should be using ENT_REMOVE to remove entities, not ptr_remove.
I've found ptr_remove can be a bit sloppy on memory cleanups with entities.

2> Any memory that gets 'lost' in this process is 'hiding' in the nexus area.
This can be retrieved/recycled by using level_load or level_mark/level_free.
READ THE MANUAL CAREFULLY ON THESE COMMANDS! They can be deadly... but often necessary.

3> If you are using the commands ENT_CLONE or ENT_CLONESKIN, then there is no way
to prevent memore loss EXCEPT by using something from point#2.



BTW the way you are testing memory consumption is the best way IMHO...


I hope this helps somewhat...
© 2024 lite-C Forums