Thanks for the test with use warnings; I should do that more often. I tried the use warnings; and reproduced the problem. The following code fixes that issue. And it also has the proper behavior of the $v variable being changed by the subroutine. That is good. But it still leaks memory. That is bad. Now at about 1000k/second.
Also you will see that the flags showing the type of the $vr varible no longer have the VT_BYREF flag (that would be 0x6...)
# OLE Variant memory test
use strict;
use warnings;
use Win32::OLE::Variant;
for my $i ( 0 .. 10000 )
{
my $v = Win32::OLE::Variant->new(VT_ARRAY|VT_BSTR, [1,1000]);
$v->Put(1, "not changed");
# Do something here to make $vr a separate variant that points to th
+e data in $v
my $vr = Win32::OLE::Variant->new(VT_ARRAY|VT_BSTR|VT_BYREF, [1,1000
+]);
$vr = $v;
DoStuff(\$vr); # modify $vr and see if $v has changed
printf "0x%04x, %s; 0x%04x, %s\n", $v->_RefType(), $v->Get(1), $vr->
+_RefType(), $vr->Get(1);
undef $v;
}
print STDERR "Waiting..."; # give time to watch process in Windoze Tas
+k Mangler
sleep(5);
print STDERR "Done.\n";
sub DoStuff
{
my $refVar = shift; # reference to the Variant
for my $i ( 1 .. 1000 )
{
$$refVar->Put($i, "Fred and barney are funny $i");
}
}
But I still like the proposed ByRef() method to make a variable that points to another one. (See responses to the Re^3 reply to this post.)