I have tested a new version of Win32::OLE that allows the following program to work ("work"=pass all module tests and not leak memory when running while monitored using the Task Mangler). Any thoughts about how to get this reviewed and maybe into the CPAN release?
# 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 al +locations { 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 th +e 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 explici +tly. # Instead we make a variant without the VT_BYREF flag, then call B +yRef() # 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 usa +ge print STDERR "Done.\n"; sub DoStuff { my $refVar = shift; for my $i ( 1 .. 1000 ) { $refVar->Put($i, "bar $i"); } }

In reply to Re^4: Avoiding Memory Leaks with Win32::OLE (proposed fix) by vpmeister
in thread Avoiding Memory Leaks with Win32::OLE by vpmeister

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.