Massive memory leak witnessed as of v4.22

Posted by Vchat20 on Mon 17 Mar 2008 08:20 AM — 10 posts, 34,860 views.

USA #0
This is an awful weird case I have noticed lately and mostly due to the fact my primary machine has only 512MB to work with.

I figure screenshots/images will explain more than what I can in words:
Process Explorer: http://img262.imageshack.us/img262/1421/03172008034614bk6.png
M*U*S*H Info: http://img262.imageshack.us/img262/3162/03172008042348dn6.png

I only have two worlds running and the second one other than M*U*S*H has only a few hundred lines in the buffer. I only have a few plugins running on each like reconnector, hyperlink2, grab, and showactivity.

To me it seems awfully odd for it to be using so much memory, virtual and physical, especially seeing as it's never been anywhere near this high in older versions.
Amended on Mon 17 Mar 2008 08:22 AM by Vchat20
Netherlands #1
I have about the same memory usage, but my plugin/trigger count exceeds the 3000 and my buffer takes 11MB at present. Of course, I haven't paid much attention to memory usage lately, but maybe sometihng on your machine changed? A plugin that goes wonky or something in the new version, perhaps?
USA #2
To isolate this, it would probably help to see the memory usage without any plugins enabled. If it goes away, that suggests that the problem is in either the plugins, or in the plugin engine somewhere, and not the MUSHclient core.
Australia Forum Administrator #3
This has been discussed at some length here:

http://www.gammon.com.au/forum/?id=6023

Your thread description says "as of v4.22" - does that mean it was less noticeable in an earlier version? If so, which version? If you revert to the earlier version (but don't change anything else, if possible) does the problem go away?

There is a known problem, which is unresolved so far, that if you have:

  • A trigger/timer/alias that is called frequently
  • It does "send to script" (rather than calling a script function in a separate script file)
  • It uses a script language other than Lua


... this seems to cause gradual memory leaks.

When you use "send to script" the script engine is called to "compile" and then "execute" your script (each time). It appears that calling the compile phase frequently is somehow to blame. If you use a script file this is only compiled once, and thus any leaks are minimized.

Lua is implemented differently internally (it doesn't use the Windows Script Interface) and does not have this problem.

The problem would also apply to any plugins you have installed that meet that criteria.

It is likely to be particularly noticeable if you do something very frequently, for example a trigger that matches every line (eg. to log each line).

MUSHclient is Open Source, and if anyone can see the problem in the "send to script" part they are welcome to let me know.

As a workaround, I suggest doing one of these:

  • Change from "send to script" to using a script file, and calling functions in the script file. In many cases this is a simple change, the hardest part being revamping how wildcards are processed.

    For example, instead of using %1 as the first wildcard in "send to script", in the script file you need to use wildcards [1] - or whatever the exact syntax is for your language.
  • Rewrite to use Lua scripting. This lets you keep "send to script" but means learning a new script language, and implementing it.

Australia Forum Administrator #4
Since I see you only have 1 trigger, which didn't fire, it seems the trigger in your main world is not the culprit. The timer that fired 2475 times might possibly be, if it does "send to script".

Otherwise I would try disabling or removing the plugins as a temporary measure, and see if things improve. That might at least show which is responsible.
#5
Sorry for my English.

When call GetVariable method, memory leak at v4.18

<timers>
<timer enabled="y" second="1.00" send_to="12"
>
<send>for i=1,500 do
GetVariable("exp")
end</send>

</timer>
</timers>

<variables>
<variable name="exp">3000088</variable>
</variables>
Australia Forum Administrator #6
I confirm there seems to be some sort of problem with memory leaks, more serious than I originally realized. Try this (Lua) code in the Immediate window (Ctrl+I):


SetVariable ("exp", "3000088")

for i=1,50000 do
   GetVariable("exp")
end


This seems to cause MUSHclient's memory footprint to jump by about 1960 Kb each time you run it.

I am investigating why this is happening. Naturally it isn't supposed to. ;)
Australia Forum Administrator #7
It appears there is a bug in the way that strings are passed back to Lua from MUSHclient function calls. Basically every function call that returned a string (GetVariable being one of many) would make a copy of the string, and the original was not freed.

This will be fixed in version 4.25.

The memory leak only applies to Lua scripting (however there are known problems with memory leaks in other script languages, so please don't ditch Lua just yet).
Australia Forum Administrator #8
Version 4.25 has now been released, so try it with that.
#9
This bug is fixed.
thanks a lot.