Re: make perl release memory
by Elian (Parson) on Jun 19, 2003 at 17:24 UTC
|
This isn't necessary. On some operating systems, Windows included, perl will release blocks of free memory back to the system when it's done with them. There are some limitations on this that you have basically no control over, but if you're running Win32, MacOS, VMS, or with some versions of glibc, memory will get released back to the system (not just back to the process' free pool) when it is completely unused.
This process isn't guaranteed. For a chunk of memory to be released it must be of sufficient size to be worth it (glibc puts a minimum allocation size somewhere in the megabyte range to trigger allocation of a releaseable segment) and it must be completely empty. If the allocation size is too small what'll happen is that a larger block will be allocated and parcelled out in pieces by the C library. This larger block will often (though not always) be releasable, but since it's been carved into a zillion little pieces it rarely will ever be completely unused and thus released. Some systems also place a minimum hold time of some sort on the chunks, and won't release them immediately in case space is needed, to save the time spent freeing and then reallocating the space.
Basically if you allocate 100M in one chunk, it'll get released back to the system when unused. If you allocate 100M in 100 byte chunks, it'll never get released.
There's not much you can do with the current perl 5 source to make this happen any differently. Perl already does the right thing, and its up to the system and runtime libraries to decide whether chunks should be released. Unfortunately interpreters are rather complex beasts and making things work differently is a non-trivial and counterintuitive process. | [reply] |
Re: make perl release memory
by broquaint (Abbot) on Jun 19, 2003 at 14:48 UTC
|
Unless you're OS supports processes releasing memory back to the system while running this can't be done. See. Memory usage and perl for another discussion on this very topic.
HTH
_________ broquaint | [reply] |
|
| [reply] |
|
main()
{
char *foo = (char *)malloc(1000000);
getch();
free(foo);
getch()
}
Examined in task manager would suggest not, of course this is highly unscientific and someone else might know different.
/J\
| [reply] [d/l] |
|
Using free(ptr) will just make available the memory pointed to by ptr in the process' memory pool, not to the OS at large. This memory freeing behaviour isn't Win32 specific, but applies to most modern OSes.
HTH
_________ broquaint
| [reply] |
|
| [reply] |
Re: make perl release memory
by Jenda (Abbot) on Jun 19, 2003 at 16:11 UTC
|
Ask them to look at the other processes. If I look at my
processes I see four IEXPLORERs with 10-15MB, SiteView (in-house tool for web automation) 15 MB, ProductTranslator 14MB, svchost 10MB, DLLHOST 10MB, inetinfo 9MB, MCSHIELD 9MB, etc. etc. etc. etc.
Maybe it would also help if you told them that a VB program as small as this:
Sub Main()
MsgBox "Ahoj Jendo", vbInformation, "Greeting"
End Sub
takes up as much as 3MB of memory according to the Task Manager.
In either case I think the best solution would be to disable the Task Manager for those users ;-)
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature | [reply] [d/l] |
|
I've tried this argument as well, pointing out that iexplore often consumes more memory than my app. mysqld consumes around 40MB; opera takes about 25MB. I personally don't see much of a problem with these figures, so I think I may just have to give up on these users. If they're not willing to recognize that 25MB _isn't that bad_ then forget them. :)
The other thing is that when I open new windows in my app (it's Tk-based) or perform certain actions, the memory increases slightly. I've personally never seen it go beyond 27MB, even after days of usage and hundreds of windows being opened. So I guess what I want to know is: is this indicative of a memory leak, or is it something I shouldn't worry about?
This project can be downloaded from the link in my sig if anyone feels the need to test it out.
Thanks for your answers, everyone!
Bill
milkbone - perl/tk instant messaging - it's the only way to fly
| [reply] |
|
If you open and close the same window many times does the used memory keep growing? If not then there's no leak in that part. It's next to impossible to prove a program has no leaks (especialy in Perl), but if you run it for long and do not see a problem I don't think it's necessary to care much :-)
As someone (sorry don't remember who) has in his/her signature: Worry only about the things you have to implement.
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature
| [reply] |
|
| [reply] [d/l] |
|
|
|