vpmeister has asked for the wisdom of the Perl Monks concerning the following question:
If the Variant is created without the VT_BYREF then it is cleaned up properly and there is no leak. I think what should happen is that $v should be created without the VT_BYREF, and then I create a new Variant, $vr, which has the VT_BYREF attribute and points to the data in $v. Then i can pass $vr to the DoStuff(). DoStuff modifies the values, which are really also the values in $v. Then when it comes time to clean up, the array data in $vr is not released, but it is in $v. So the question is: How do I do something like: my $vr = $v; such that $vr now has the VT_BYREF attribute and points to the same data in $v? Here is the latest test code I am working with:# OLE Variant memory test use strict; use Win32::OLE::Variant; for my $i ( 0 .. 10000 ) { my $v = Win32::OLE::Variant->new(VT_ARRAY|VT_BSTR|VT_BYREF, [1,1000] +); DoStuff(\$v); 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"); } }
# OLE Variant memory test use strict; use Win32::OLE::Variant; for my $i ( 0 .. 0 ) { 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, $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"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Avoiding Memory Leaks with Win32::OLE (what leaks)
by Anonymous Monk on Oct 17, 2015 at 00:13 UTC | |
by vpmeister (Novice) on Oct 18, 2015 at 21:44 UTC | |
by Anonymous Monk on Oct 18, 2015 at 22:41 UTC | |
by vpmeister (Novice) on Oct 25, 2015 at 05:54 UTC | |
by vpmeister (Novice) on Oct 25, 2015 at 06:20 UTC | |
by vpmeister (Novice) on Oct 25, 2015 at 07:11 UTC | |
|
Re: Avoiding Memory Leaks with Win32::OLE
by u65 (Chaplain) on Oct 16, 2015 at 22:53 UTC |