Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Avoiding Memory Leaks with Win32::OLE (what leaks)

by vpmeister (Novice)
on Oct 25, 2015 at 07:11 UTC ( [id://1145878]=note: print w/replies, xml ) Need Help??


in reply to Re: Avoiding Memory Leaks with Win32::OLE (what leaks)
in thread Avoiding Memory Leaks with Win32::OLE

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.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1145878]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found