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.