Dear Group,
I've made a simple stufy regarding memory deallocation and threads with
ActivePerl 5.8.6;
This simple script taken from the documentation takes up infinite memory.
Anyone sees any problem, or knows a workaround?
use threads;
my $thr;
for (;;) {
$thr = threads->new(\&sub1);
$thr->detach(); # bug also present with $thr->join()
sleep 1;
}
sub sub1 { print "In thread!\n"; }
Another interesting issue is that adding an explicit undef clears up memory
...
for (;;) {
$thr = threads->new(\&sub1);
$thr->detach(); # bug also present with $thr->join()
undef $thr; # crazy attempt
sleep 1;
}
and works with the sample script, but with my complicated program, it fails
with some ugly messages
Win32::OLE(0.1702): GetOleObject() Not a Win32::OLE object at
C:/Perl/site/lib/Win32/OLE/Lite.pm line 221.
Win32::OLE(0.1702): GetOleObject() Not a Win32::OLE object at
C:/Perl/site/lib/Win32/OLE/Lite.pm line 221.
Win32::OLE(0.1702): GetOleObject() Not a Win32::OLE object at
C:/Perl/site/lib/Win32/OLE/Lite.pm line 221.
Win32::OLE(0.1702): GetOleObject() Not a Win32::OLE object at
C:/Perl/site/lib/Win32/OLE/Lite.pm line 154.
Can't call method "Refresh" on an undefined value at
module/base/DataService.pmline 122.
Attempt to free non-existent shared string 'Open', Perl interpreter:
0x224014 at (eval 1) line 1.
Attempt to free non-existent shared string 'State', Perl interpreter:
0x224014 at (eval 1) line 1.
Free to wrong pool 223f50 not ab35988 at (eval 1) line 1.
This is disturbing. If perl is not deallocating memory naturally, I suppose
that there is some internal reference
to the thread. But the thread is supposed to be detached! That's strange
thing #1;
Strange thing #2 : On the other hand, when I explicitly undef $thr, and perl
deallocate it, that means $thr was the only reference to
the thread object. But if that is true, why in the first place didn't perl
deallocate the thread object when I overwrote the
reference with a new thread?
Thanks in advance. I look forward to hear a bit of the wisdom and experience
of the more experienced perl programmers from this list
My best regards,
Gabriel