Question

I followed the top answer here, see below for code to get system memory being used at a given line in my perl code. I'm running Windows 7 Home Basic, 64 bit, 4 GB ram, 4.06 GB Virtual memory (As specified under advanced system settings under My computer). I got following message from perl at a line, before perl goes Out of Memory.

Memory usage: 1916346368

Assuming that this number is in bytes (= 1.78 GB), why did perl go Out of Memory? How can I get system total memory usage by all the processes?

Code block to compute memory is as below. I'm using Strawberry Perl 5.12.3.0

use Win32::OLE qw/in/;

sub memory_usage() {
    my $objWMI = Win32::OLE->GetObject('winmgmts:\\\\.\\root\\cimv2');
    my $processes = $objWMI->ExecQuery("select * from Win32_Process where ProcessId=$$");

    foreach my $proc (in($processes)) {
        return $proc->{WorkingSetSize};
    }
}

print 'Memory usage: ', memory_usage(), "\n";

Perl -V gives following info http://pastebin.com/mvF7YgKH

Update: The problem got solved with 64 bit perl. But I also noticed that the program ran w/o hitch on 32 bit perl on Ubuntu. So, may be Strawberry perl on Windows takes more memory than perl on Ubuntu.

Was it helpful?

Solution

If you were trying to allocate, or reallocate, an enormous string, array or hash it could have requested a larger memory block than was available from the system. While you have 4 gigs of real memory and 4 gigs of virtual, other processes might have been consuming a large chunk of that.

Alternatively, your system might have a per process memory limit which would might be 2 gigs.

Finally, your OS may be 64 bit, but your Perl may be 32 bit. In that case the maximum amount of memory it can address would be 2 gigs. If you post a copy of perl -V somewhere we can view we might be able to work that out.

OTHER TIPS

You have 32-bit Perl. It is not surprising that Windows cannot allocate more than 2GB or memory to 32-bit process. If you install 64-bit Perl, this should max out at physical RAM.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top