Posted By: Carlos3DGS
ent_create and memory leaks - 03/01/12 15:10
Some time ago I learned in thread on this forum that there was a problem with the ent_create() function.
As I understood the conversation, when you ent_create() memory is allocated for that entity, but on removal it is not completely freed, most of it is excluding a small part.
This was a huge problem for me because I dynamically create the world as the player moves along and remove the parts left behind to create a theoretically "infinite" sized world. I thought that this small "memory leack" would be problem in long gameplay sessions since it would gradually stack up and could cause problems with enough time...
Because of this problem I designed a system to compliment the ent_create and ent_remove functions. It is basically a linked list of entity pointers. What it does is whenever an entity is removed, instead of removing it makes it invisible and places it well below the level and adds it to the "avalable entities linked list". Whenever you create a new entity I first check this list, if it is not empty the last entity on the list is re-used using ent_morf, visible flag is set, moves it to the desired position, and removed from the "available entities linked list". Only when this "entity recycle bin" is empty new entities are created in the traditional way.
I was wondering if sprites were also causing this problem (since they are also created useing ent_create)so I wrote a test to confirm if they had to use this system also or not...
To my surprize it seems like it does not cause any memory leack, so I decided to test if it really does cause a small memory leack with models:
To my surprize it seems that there is no memory leack. But this was said by a veteran of the forum and I do trust his knowledge and skills. So mabe there is something wrong with my tests? Or I am looking at the wrong variables in the "F11" panel?
The starting values in the F11 panel under "memory MB" column were:
nex 9
mem 241
geo 0
shd 0
ent 0
fre 2037
currently this last test has been going for around an hour and these values have not changed and is still running with no changes while I write this post.
Under the column "count of" the values for ent and vis go constantly from 1000 to 0 so it is creating and removing entities.
fps is always around 170 so if you do the math 170x1000
and multiply the time it has been running for x60x60
you get 612000000 entities have been created and removed with no change in the "memory MB" column of the F11 panel during this test.
I wanted to put this out there to get other experienced users' opinions on it.
-Is my test correct to verify an ent_create memory leack?
-Is the F11 panel enough info to draw a conclusion on this or is there a better way to test this?
-Is there any other info in the F11 panel I should be looking at?
-Has the ent_create memory leack been fixed in any patch/version that I am not aware of?
-What are your experiences with this issue?
-What is the pps variable in the F11 panel's first column?
As I understood the conversation, when you ent_create() memory is allocated for that entity, but on removal it is not completely freed, most of it is excluding a small part.
This was a huge problem for me because I dynamically create the world as the player moves along and remove the parts left behind to create a theoretically "infinite" sized world. I thought that this small "memory leack" would be problem in long gameplay sessions since it would gradually stack up and could cause problems with enough time...
Because of this problem I designed a system to compliment the ent_create and ent_remove functions. It is basically a linked list of entity pointers. What it does is whenever an entity is removed, instead of removing it makes it invisible and places it well below the level and adds it to the "avalable entities linked list". Whenever you create a new entity I first check this list, if it is not empty the last entity on the list is re-used using ent_morf, visible flag is set, moves it to the desired position, and removed from the "available entities linked list". Only when this "entity recycle bin" is empty new entities are created in the traditional way.
I was wondering if sprites were also causing this problem (since they are also created useing ent_create)so I wrote a test to confirm if they had to use this system also or not...
Code:
#include <acknex.h> #include <default.c> ENTITY* test[1000]; int i; void main() { level_load(NULL); wait(3); vec_fill(camera.x,0); camera.z=1000; vec_fill(camera.pan,0); camera.tilt-= 90; while(1) { for(i=0;i<1000;i++) { test[i]=ent_create("ModernArtSucks.bmp",nullvector,NULL); } wait(1); for(i=0;i<1000;i++) { ent_remove(test[i]); } wait(1); } }
To my surprize it seems like it does not cause any memory leack, so I decided to test if it really does cause a small memory leack with models:
Code:
#include <acknex.h> #include <default.c> ENTITY* test[1000]; int i; void main() { level_load(NULL); wait(3); vec_fill(camera.x,0); camera.z=1000; vec_fill(camera.pan,0); camera.tilt-= 90; while(1) { for(i=0;i<1000;i++) { test[i]=ent_create("test.mdl",nullvector,NULL); } wait(1); for(i=0;i<1000;i++) { ent_remove(test[i]); } wait(1); } }
To my surprize it seems that there is no memory leack. But this was said by a veteran of the forum and I do trust his knowledge and skills. So mabe there is something wrong with my tests? Or I am looking at the wrong variables in the "F11" panel?
The starting values in the F11 panel under "memory MB" column were:
Quote:
nex 9
mem 241
geo 0
shd 0
ent 0
fre 2037
currently this last test has been going for around an hour and these values have not changed and is still running with no changes while I write this post.
Under the column "count of" the values for ent and vis go constantly from 1000 to 0 so it is creating and removing entities.
fps is always around 170 so if you do the math 170x1000
and multiply the time it has been running for x60x60
you get 612000000 entities have been created and removed with no change in the "memory MB" column of the F11 panel during this test.
I wanted to put this out there to get other experienced users' opinions on it.
-Is my test correct to verify an ent_create memory leack?
-Is the F11 panel enough info to draw a conclusion on this or is there a better way to test this?
-Is there any other info in the F11 panel I should be looking at?
-Has the ent_create memory leack been fixed in any patch/version that I am not aware of?
-What are your experiences with this issue?
-What is the pps variable in the F11 panel's first column?