Yes, here are the numbers. When the test program posted in the original question is run with the outermost loop going from (0 .. 10000), the program gains between 4K and 10K/second in the Task manager.

What I modified. I added the code in OLE.xs to do a SafeArrayDestroy() on the SAFEARRAY* even if the variant has the VT_BYREF flag set. More specifically, immediately after the switch statement, but still inside the if() (at line 2333--maybe), in void ClearVariantObject(WINOLEVARIANTOBJECT *pVarObj), I added the following code,

/* 14-Oct-2015 WDJ Added to avoid memory leak of byref arrays +*/ if ( vt & VT_ARRAY ) /* this is an array byref */ { /* printf("WDJ doing additional SafeArrayDestroy\n"); */ SAFEARRAY *psa = *V_ARRAYREF(pVariant); if ( psa ) SafeArrayDestroy(psa); } /* printf("WDJ Calling VariantClear in addition to VariantInit +\n"); */ /* VariantClear(pVariant); */

The VariantClear(pVariant); that is commented out at the last line it likely not necessary, because the proper clean up was (hopefully) done manually above.

But since I did the above change on 14 Oct, I am working on updating the code to follow the plan I outlined in the original post, which adds a ByRef() method that will create a VT_BYREF version of the Variant so it can be passed to subroutines, etc. Stay tuned.

And yes, I e-mailed the original developer--no response yet. I'll ask around with my Python friends to see if they have done a similar thing.


In reply to Re^4: Avoiding Memory Leaks with Win32::OLE (what leaks) 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.