DaWolf has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, fellow monks.

I'm developing an IRC Bot with Perl and Net::IRC that runs on my personal machine (Windows 2000 Professional, ActivePerl 5.8.0) and I've detected a somewhat odd problem:

When I play an on-line game like Wolfenstein: Enemy Territory the memory usage of wperl.exe jumps from 7.7 Mb to 10.0 Mb and never drops again, unless I kill the bot and start it again.

<UPDATE>
Funny thing: if I play the game again there is no more growth in the memory usage, it stays at 10.0 Mb...
</UPDATE>

I use the standard connection sub of Net::IRC and I have a sub that detects if the bot's IRC connection drops and it's not happening...

Are there any theoretical possibilities for this problem?
Are there any modules that can help me find out the cause for this problem?

I've already been told to use POE::Component::IRC instead of Net::IRC, but it's way above my capabilities, so please keep in mind that this is not an option for me.

Thanks in advance for the enlightment, brothers and sisters.

my ($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br") if ($author_name eq "Er Galvão Abbott");
  • Comment on Reasons for memory growth on Win32 IRC Bot app

Replies are listed 'Best First'.
Re: Reasons for memory growth on Win32 IRC Bot app
by BrowserUk (Patriarch) on Dec 03, 2003 at 00:46 UTC

    There really isn't enough information in your post to diagnose what might be the source of the memory consumption, but I would hazard a guess that when you play the online game in question, this causes the IRCbot to dynamically load one of it's dependancies that consumes some extra memory? For example, IO::Socket::SSL is loaded dynamically when a SSL connecting is required. Could this be the source of the memeory consumption?

    That said, 2 and a bit megs is little enough these days that it hardly seems worth worrying about. If the increase occurred every time you made a new connection it would be worrying, but as a one time hit it seems more than acceptable for the functionality you are getting as a result.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!
    Wanted!

Re: Reasons for memory growth on Win32 IRC Bot app
by Ninthwave (Chaplain) on Dec 03, 2003 at 13:17 UTC

    A discussion on this. A discusson on releasing memory in Perl

    I swear I was reading on Perl memory somewhere that it will not allocate back to the system memory until perl.exe or in your case wperl.exe exits. Or this may have been a discussion on what we were seeing with ithreads running. But it sounds like it allocates memory and has not released it to the system, though it has been freed for Perl to use, so when your bot needs the memory again it does not need to request more from the system.

    To me this seems like the right thing to do because if Perl releases the memory back to the system and the program needs it again this passing of memory back and forth between system and Perl could be costly.

    And actually I would have to say that is how perl works on Win32 at least it will keep all the memory it has allocated free or not until the program ends. We tested that by running our thread script and adding a loop at the end after all the threads had ended. I am going to do a test to see if we can force it to free memory by destroying all variables before looping.

    Updated:

    From the second document:
    On most operating systems, memory allocated to a program can never be returned to the system. That's why long-running programs sometimes re-exec themselves. Some operating systems (notably, systems that use mmap(2) for allocating large chunks of memory) can reclaim memory that is no longer used, but on such systems, perl must be configured and compiled to use the OS's malloc, not perl's. However, judicious use of my() on your variables will help make sure that they go out of scope so that Perl can free up that space for use in other parts of your program. A global variable, of course, never goes out of scope, so you can't get its space automatically reclaimed, although undef()ing and/or delete()ing it will achieve the same effect. In general, memory allocation and de-allocation isn't something you can or should be worrying about much in Perl, but even this capability (preallocation of data types) is in the works.
    I knew I was reading this somewhere.

    The tests I have done. Basically confirm that on the ActiveState build this is the case whatever memory Perl takes you do not get back to the Operating Sytem until the program exits. But by having variables go out of scope and passing by reference you can limit the amount of memory that perl takes from the system in total.

    I would ask the more venerable here if they have any tricks that can get memory back to the system but I do see anything obvious that could be done to accomplish this.

    "No matter where you go, there you are." BB
      Could you tell me when you get the results from this test?

      Thanks a lot.

      my ($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br") if ($author_name eq "Er Galvão Abbott");