Hi,
I am trying to experiment with memory allocation in Perl and I hit a problem with Perl crashing out of memory.
I am using Win32 XP Pro.
Here is the code:
#!/usr/bin/perl
use FindBin qw($Bin);
use lib "$Bin/";
use strict;
my @idsMap;
my @h_item_selector;
my $cnt = 1;
for(my $i = 1; $i < 50; $i++)
{
my $start = "aaa";
for(my $j = 1; $j < 250000; $j++)
{
my $val = "$cnt $i $j $start";
$h_item_selector[$i] -> {$val} = $cnt;
$cnt++;
$start++;
}
}
undef (@h_item_selector);
print "did undef of array\n";
sleep 10;
print "alocating string array\n";
my $g_freeSelectorIndex = 10000000;
for(my $i = 0; $i < $g_freeSelectorIndex;$i++)
{
if( ($i % 10000) == 0)
{
print "Processing $i element\n";
}
$idsMap[$i] = -1;
if( ($i % 10000) == 0)
{
print "Processed $i element\n";
}
}
I am creating a large array of hashes, which goes up to around 1.8GB of memory usage. I then undef the array, and try to create another array that will hold 10M integers.
Perl crashes after allocating around 4.2M array elements in the new array.
I thought that after I did undef, Perl could reuse the memory that was freed.
However, it looks like after freeing memory, the program still causes Perl to run out of memory.
Please advise me of what could be causing Perl to not properly reuse the freed memory.
I tried the same program on OSX, and it worked there and didn't crash.
This is just a test program that simulates behavior of a real script I have.
Thanks for your help.
Regards,
Tim
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.