Memory increasing question

Non-platform specific questions.

Memory increasing question

Postby Leif » Tue May 24, 2011 4:52 am

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?
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Memory increasing question

Postby again » Tue May 24, 2011 11:13 am

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.
Free windows mobile games like doodle jump and super mario bros
http://krenisis.freeforums.org/
again
 
Posts: 258
Joined: Wed Jan 19, 2011 7:06 pm
Score: 33 Give a positive score

Re: Memory increasing question

Postby akr » Tue May 24, 2011 7:14 pm

Can u send me a small example I can reproduce the problem? I am willing to check this.
Co-Developer of GE engine

If u are interrested in new features of apple or android ge engines check the engine support website game-editor.net regulary.
akr
 
Posts: 453
Joined: Thu Feb 25, 2010 7:56 pm
Location: Germany, Ulm
Score: 40 Give a positive score

Re: Memory increasing question

Postby Leif » Wed Oct 12, 2011 6:57 pm

Finally i get it !! :D
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.

Lightning.zip
(15.08 KiB) Downloaded 100 times
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Memory increasing question

Postby EvanBlack » Thu Oct 13, 2011 1:39 am

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);
}

Last edited by EvanBlack on Thu Oct 13, 2011 2:06 am, edited 1 time in total.
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Memory increasing question

Postby Hblade » Thu Oct 13, 2011 2:05 am

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.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Memory increasing question

Postby EvanBlack » Thu Oct 13, 2011 2:15 am

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) ;

(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Memory increasing question

Postby Hblade » Thu Oct 13, 2011 3:23 am

Genius.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Memory increasing question

Postby skydereign » Thu Oct 13, 2011 4:34 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Memory increasing question

Postby Leif » Thu Oct 13, 2011 6:18 am

wow !!!!! :D :D

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 ?
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Memory increasing question

Postby skydereign » Thu Oct 13, 2011 6:22 am

Code: Select all
Actor *
getclone2 (char * cname, int cindex)
{
    char buffer[50];
    sprintf(buffer, "%s.%d", cname, cindex);
    return(getclone(buffer));
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Memory increasing question

Postby Leif » Thu Oct 13, 2011 9:22 am

Well, thanks...
Skydereign, can you write part of code with using it ? For me it's not clear :oops:
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Memory increasing question

Postby Leif » Thu Oct 13, 2011 12:24 pm

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);
}
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Memory increasing question

Postby EvanBlack » Thu Oct 13, 2011 6:25 pm

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);
)
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Memory increasing question

Postby Leif » Fri Oct 14, 2011 3:34 am

Ок, 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... )
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest