# OLE Variant memory test use strict; use Win32::OLE::Variant; for my $i ( 0 .. 10000 ) # Do many times so we have a lot of memory allocations { my $v = Win32::OLE::Variant->new(VT_ARRAY|VT_BSTR, [1,1000]); $v->Put(1, "foo"); # Do something here to make $vr a separate variant that points to the data in $v # my $vr = Win32::OLE::Variant->new(VT_ARRAY|VT_BSTR|VT_BYREF, $v); <-- LEAK in ver 0.1712 # With version 0.1714, we never make a Variant with VT_BYREF explicitly. # Instead we make a variant without the VT_BYREF flag, then call ByRef() # on it to return a reference. my $vr = $v->ByRef(); DoStuff( $vr ); # modify and see if $v has changed if ( $i == 0 ) { # next line should print: 0x2008, bar 1; 0x6008, bar 1 printf "0x%04x, %s; 0x%04x, %s\n", $v->_RefType(), $v->Get(1), $vr->_RefType(), $vr->Get(1); printf "0x%04x, %s; 0x%04x, %s\n", $v->_RefType(), $v->Get(2), $vr->_RefType(), $vr->Get(2); } undef $v; } # while this loop is running, check the Task Mangler for memory usage print STDERR "Done.\n"; sub DoStuff { my $refVar = shift; for my $i ( 1 .. 1000 ) { $refVar->Put($i, "bar $i"); } }