Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
horks
Apprentice


Joined: 20 Jul 2001
Posts: 127
Location: USA

PostPosted: Wed Sep 10, 2003 5:16 pm   

Memory Leak in zMUD v6.62
 
Hello,

I seem to have found a memory leak in zmud. It's caused my a very long alias that i have being called every round. I haven't tried to pinpoint which part of the alias is causing the memory leak yet, sorry. I'll followup when I do.

Code:

#VARIABLE hppercent %eval( @hp*100/@hpmax)
#VARIABLE hp5p %eval( @hpmax/10)
#VARIABLE hptick %eval( @hp/@hp5p)
#IF (@hptick>=10) {#VARIABLE hpshow @bar10} {
 #IF (@hptick=9) {#VARIABLE hpshow @bar9} {
 #IF (@hptick=8) {#VARIABLE hpshow @bar8} {
 #IF (@hptick=7) {#VARIABLE hpshow @bar7} {
 #IF (@hptick=6) {#VARIABLE hpshow @bar6} {
 #IF (@hptick=5) {#VARIABLE hpshow @bar5} {
 #IF (@hptick=4) {#VARIABLE hpshow @bar4} {
 #IF (@hptick=3) {#VARIABLE hpshow @bar3} {
 #IF (@hptick=2) {#VARIABLE hpshow @bar2} {
 #IF (@hptick=1) {#VARIABLE hpshow @bar1} {
 #IF (@hptick=0) {#VARIABLE hpshow ""}
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
#IF (@hptick>10) {#VARIABLE hpcol {high,yellow}} {
 #IF (@hptick>9) {#VARIABLE hpcol {high,cyan}} {
 #IF (@hptick>7) {#VARIABLE hpcol {cyan}} {
 #IF (@hptick>5) {#VARIABLE hpcol {high,green}} {
 #IF (@hptick>3) {#VARIABLE hpcol {high,magenta}} {
 #IF (@hptick>=2) {#VARIABLE hpcol {high,red}} {
 #VARIABLE hpcol {red}
            }
          }
        }
      }
    }
  }
#VARIABLE hpshow %left( %concat( %left( %concat( %ansi( white)
@hppercent, ~%, "      "), 15)%left( %concat( %ansi( @hpcol)
@hpshow, "                       "), 30)), 41)


quick var rundown:

  • @hp = current hit points

  • @hpmax = max hit points

  • @hppercent = current % of max hit points

  • @hp5p = 10% of max hp (used to be 5%, but bar was too long.)

  • @hptick = how many blocks of @hp5p I currently have

  • @hpshow = the var this whole script makes

  • (also a placeholder before the bar gets ansi commands.)
  • @hpcol = color commands to be used with %ansi() later in this alias
    and also later in the status window.[/*]



What this does, is it generates a single line string that I can use in my status window. The string is a colored bar representing my hp. The string also has a lot of blank spaces in it, so that it can be placed in a precise position (hence all the %left and %concat functions at the end.) In this alias, there are actually 5 sets of code all similar to the above, cept for the variable names (my hit points, spell points, stamina, strain, and mobs hit points.)

I know I can use #guage to make nice looking guages, but I already have 12 of those Smile and these stats are a little more important to me, so I want it to stand out more than the other bars.

Anyhow, my rambling at the end was basically to say, I don't want to change how I view my data, I just want to fix this memory leak[:o)]

I first noticed it when I had been mudding for a couple hours straight, and fell asleep. when I woke up, zmud was still running, so I went right back to playing. I assuming that zmud was probably active for 12 or more hours. Then I got a 'Low Virtual Memory. Increasing Page File' update from windows. When I looked at my task manager, zmud was using over 400MB of memory!! I restarted my computer, and zmud. When zmud restarted it was consuming around 22MB, but every time this alias is activated (i.e. every round) the memory size would grow 20-60k in size.

Hope you can help me Smile I'll keep looking into it also, and try to pinpoint which part of the alias is causing the problem.




System:
AMD 1.4Ghz
512MB RAM
Windows Pro XP (SP1)
Office XP (uninstalled after zmud installation)
zMUD 6.62
Reply with quote
horks
Apprentice


Joined: 20 Jul 2001
Posts: 127
Location: USA

PostPosted: Thu Sep 11, 2003 1:56 am   
 
Well, I started trying to isolate the issue, and guess what? it's not in the code portion I posted Sad. I plugged that portion of the script into an alias, by it's self, and memory didn't grow. So, to fix this problem, I'm just going to use that portion of code, and copy it five times, then change the vars.
Reply with quote
horks
Apprentice


Joined: 20 Jul 2001
Posts: 127
Location: USA

PostPosted: Thu Sep 11, 2003 4:08 am   
 
So, I think I figured it out. After rewriting the _whole_ alias, I came up with the same problem. I started removing elements of code, and suddenly it hit me. It's the LENGTH of the alias that's the problem. When I broke the alias up into two aliases (then, in the first alias, made a call to the second alias) and the whole thing works with out a hitch.

Now that it's fixed, I'm done with it. However if someone would like me to probe at it a little more, I'd be more than willing to :)
Reply with quote
horks
Apprentice


Joined: 20 Jul 2001
Posts: 127
Location: USA

PostPosted: Thu Sep 11, 2003 4:52 am   
 
SIGH :(

It's still leaking. but i give up. I can't figure out what's wrong. Maybe too many commands at the same time? shrug. I think i've definatly got zmud running at it's fullest. My CPU usage spikes to 60-70% when a round goes by, and my scripts respond.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu Sep 11, 2003 7:15 pm   
 
#MATH hppercent (@hp * 100 / @hpmax)
#MATH hp5p (@hpmax / 10)
#MATH hptick (@hp * 10 / @hpmax)
#IF (@hp >= @hpmax) {#VARIABLE hpshow @bar10;#VAR hpcol {high,yellow}} {
#CASE ((@hp * 10) / @hpmax) {#VARIABLE hpshow @bar1;#VAR hpcol red} {#VAR hpshow @bar2;#VAR hpcol {high,red}} {#VAR hpshow @bar3;#VAR hpcol {high,red}} {#VAR hpshow @bar4;#VAR hpcol {high,magenta}} {#VAR hpshow @bar5;#VAR hpcol {high,magenta}} {#VAR hpshow @bar6;#VAR hpcol {high,green}} {#VAR hpshow @bar7;#VAR hpcol {high,green}} {#VAR hpshow @bar8;#VAR hpcol {cyan}} {#VAR hpshow @bar9;#VAR hpcol {high,cyan}} {#VAR hpshow "";#VAR hpcol {red}}
}
#VARIABLE hpshow %left( %concat( %left( %concat( %ansi( white), @hppercent, ~%, " "), 15)%left( %concat( %ansi( @hpcol), @hpshow, " "), 30)), 41)

I don't know if this will help or not. I used #MATH instead of #VAR/%eval and replaced most of the #IFs with #CASE. Since the number of statements is down, hopefully the processing time will be also.

I used high,yellow whenever hp is at or above hpmax, so I moved high,cyan to the 90-99% range. If you aren't using @hp5p and @hptick elsewhere, you can eliminate them. I didn't use them at all.

EDIT: You'll need to adjust the number of spaces in the %concat()s. The forum ate them up. Sad
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Sat Sep 13, 2003 3:56 am   
 
I see that you have done a lot of work, and I applaud you tryingv to work it out yourself.

That said here is a pretty easy way to do what you wanted.

http://www.zuggsoft.com/forum/topic.asp?TOPIC_ID=9645

Charbal's status window extender.

Tweeking this program to fit your needs is a really good way to get what you want done.

This programer did an excelent job and I have enjoyed use his finished scripts.

Hope this helps.
Reply with quote
horks
Apprentice


Joined: 20 Jul 2001
Posts: 127
Location: USA

PostPosted: Mon Sep 15, 2003 5:32 pm   
 
Lightbulb -
Reply with quote
horks
Apprentice


Joined: 20 Jul 2001
Posts: 127
Location: USA

PostPosted: Mon Sep 15, 2003 5:32 pm   
 
Lightbulb -
Reply with quote
horks
Apprentice


Joined: 20 Jul 2001
Posts: 127
Location: USA

PostPosted: Mon Sep 15, 2003 5:39 pm   
 
Lightbulb -

Thanks for the help. I used to revision. I also used your philosophy about '#VAR %eval' throughout the rest of my scripts. I also went through, and made sure I had {} around everything I'm supposed to. I also removed the @hpshow var, and put all those instructions into the status window. I don't think the status window gets processed at every change, so I was hoping that too would cut down on processes. (Am I right?)

And in the end, it still leaks :( but not as bad. Leak is now down to 16k (exactly 16k every time the script fires) and CPU spikes are down to 20%.

Megamog75 -

Thanks for the advise :) Although this information does eventually get over to my status window, my problem has nothing to do with the status window. This script is just processing data to put in the status window. I'd still have to do this even with charbal's script
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Tue Sep 16, 2003 6:35 am   
 
sounds like a fun chalange< I would love to have a look at it if you want to post it with some examples?
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net