http://www.perlmonks.org?node_id=311890


in reply to Reasons for memory growth on Win32 IRC Bot app

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
  • Comment on Re: Reasons for memory growth on Win32 IRC Bot app

Replies are listed 'Best First'.
Re: Re: Reasons for memory growth on Win32 IRC Bot app
by DaWolf (Curate) on Dec 03, 2003 at 14:16 UTC
    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");