Page 1 of 2
Memory increasing question
Posted:
Tue May 24, 2011 4:52 am
by Leif
Hi )
I noticed, that memory, used for GE game, slow increases during runtime. I mean - export game, run exported file, run task manager- and see, that in 15 minutes memory use raise from 30Mb to 200Mb.
It happens, bot not with 100% of games. Some games aviod this.
Why it happens?
How can I avoid troubles with it in future?
Re: Memory increasing question
Posted:
Tue May 24, 2011 11:13 am
by again
I learn to bypass this problem with the games I developed by deleting and creating charactor on view. Meaning I only have actors that I need on the screen my controlable charactor is on. Once an actor or clone is not needed , I have code in place to delete those actors.
Re: Memory increasing question
Posted:
Tue May 24, 2011 7:14 pm
by akr
Can u send me a small example I can reproduce the problem? I am willing to check this.
Re: Memory increasing question
Posted:
Wed Oct 12, 2011 6:57 pm
by Leif
Finally i get it !!
Problem localized. I made small program and found memory bug is happening.
I think it's because numerous
getclone repeatings.
Akr, i'll e-mail it to you.
Re: Memory increasing question
Posted:
Thu Oct 13, 2011 1:39 am
by EvanBlack
Can you elaborate a bit. I just don't understand what you mean exactly. The getclone function doesn't cause memleakage for me? Or is that only when you using exe version?
Of course, I only use as many actors as I need to display but I call getclone() many many times?
Do you ever free buffer? You are allocating a lot of memory here and I don't see it ever getting freed.. Instead it just makes a new pointer to a new space.
- Code: Select all
char*
getFullName (const char *cname, int cindex)
{
char* buffer = calloc(50,1);
sprintf(buffer,"%s.%i",cname,cindex);
return(buffer);
}
Re: Memory increasing question
Posted:
Thu Oct 13, 2011 2:05 am
by Hblade
The memory most likely increases with how far the distance of another actor is. For example if you have a scrolling actor, and you avoid him, he keeps going "left" for example, just keeping on going. His X variable keeps decreasing, below -105,105,105 for example. This causes high load.
Re: Memory increasing question
Posted:
Thu Oct 13, 2011 2:15 am
by EvanBlack
Fixed: No leak in this code
- Code: Select all
int i;
int Xprev=0;
int dMax=30;
int Xnew;
Actor*L;
for (i=0;i<480;i++)
{
char buffer[50]; //Create char array
sprintf(buffer, "p_lightning_b.%i",i); // attach clone index number to actor name.
L=getclone(buffer) ;
L->x=Xprev+rand(6)-3;
if (L->x<0-dMax) L->x=-dMax+rand(2);
if (L->x>dMax-0) L->x=dMax-rand(2);
Xprev=L->x;
}
Xprev=0;
for (i=0;i<480;i++)
{
char buffer[50];
sprintf(buffer, "p_lightning_y.%i",i);
L=getclone(buffer) ;
L->x=Xprev+rand(6)-3;
if (L->x<0-dMax) L->x=-dMax+rand(2);
if (L->x>dMax-0) L->x=dMax-rand(2);
Xprev=L->x;
}
Your memory leak was due this code:
- Code: Select all
char*
getFullName (const char *cname, int cindex)
{
char* buffer = calloc(50,1); //This allocates space
sprintf(buffer,"%s.%i",cname,cindex);
return(buffer); // this sends off the address.
}
That code right there causes a memory leak because that position never gets freed. You just allocate more and more space and never release it.
But the rest of you code needs to be fixed too, replace all those calls to that function with:
- Code: Select all
char buffer[50]; //Create char array
sprintf(buffer, "p_lightning_y.%i",i); // attach clone index number to actor name.
L=getclone(buffer) ;
Re: Memory increasing question
Posted:
Thu Oct 13, 2011 3:23 am
by Hblade
Genius.
Re: Memory increasing question
Posted:
Thu Oct 13, 2011 4:34 am
by skydereign
I would suggest instead of using getFullName to using a function that gets the Actor * directly. But even if you don't, then just changing your function so you don't use calloc would be better. That way you keep the function.
Re: Memory increasing question
Posted:
Thu Oct 13, 2011 6:18 am
by Leif
wow !!!!!
Thanks, EvanBlack !! It will really help. Now I know? , that it's not GE bug, but mine )))
Btw, what's the function that gets the Actor * directly ?
Re: Memory increasing question
Posted:
Thu Oct 13, 2011 6:22 am
by skydereign
- Code: Select all
Actor *
getclone2 (char * cname, int cindex)
{
char buffer[50];
sprintf(buffer, "%s.%d", cname, cindex);
return(getclone(buffer));
}
Re: Memory increasing question
Posted:
Thu Oct 13, 2011 9:22 am
by Leif
Well, thanks...
Skydereign, can you write part of code with using it ? For me it's not clear
Re: Memory increasing question
Posted:
Thu Oct 13, 2011 12:24 pm
by Leif
Hmm... this does not work...what's wrong ?
- Code: Select all
getFullName (const char *cname, int cindex)
{
//char* buffer = calloc(50,1);
//sprintf(buffer,"%s.%i",cname,cindex);
//return(buffer);
char buffer[50]; //Create char array
sprintf(buffer,"%s.%i",cname,cindex); // attach clone index number to actor name.
return(buffer);
}
Re: Memory increasing question
Posted:
Thu Oct 13, 2011 6:25 pm
by EvanBlack
Most likely because buffer clears after the function runs. Meaning it doesn't exist. But more than likely.... if you didn't just remove it by accident.
char getFullName ( const char *cname, int cindex)
Use this:
- Code: Select all
Actor * //set function to return actor pointer
getclone2 (char * cname, int cindex)
{
char buffer[50];
sprintf(buffer, "%s.%d", cname, cindex);
return(getclone(buffer)); //return actor pointer to clone
}
You would use it like:
- Code: Select all
Actor* L;
for(i; i < number; ++i)
{
L = getclone2( "p_Lightning_b", i);
)
Re: Memory increasing question
Posted:
Fri Oct 14, 2011 3:34 am
by Leif
Ок, thanks )
I'll use it from now on.
But...I already have thousand of getFullName functions in code (another game). How can I remake this function to work properly ? It's almost impossible to rewrite code for getclone2 instead of getclone(getFullName... )