I am importing data from a COM Object into perl for processing. The data is passed in a SafeArray by reference. I have memory leak and run out of memory rapidly (a large amount of data is passed to perl). The relevant variable is: $pvarMassList. I am hoping someone can tell me how to deallocate the memory associated with $pvarmassList after I copy the data into perl. As this script runs, I can watch the memory increase in the Windows Task Manager. Any help is greatly appreciated. Thanks.
use strict; use Win32::OLE; use Win32::OLE::Variant qw(:DEFAULT nothing ); Win32::OLE->Option( Warn => 3 ); # Create MSFileReader object, must have MSFileReader dll installed my $thermo_raw_file = eval{Win32::OLE->new('MSFileReader.XRawfile.1', sub{$_[0]->Close; +})}; if($@){ die "Could not create XRawfile object. This function requires Thermo + MSFileReader\n"; } # Open raw file and set controller to first(1) mass spec device (0) $thermo_raw_file->Open("RSK2017C.RAW"); $thermo_raw_file->SetCurrentController(0,1); my @TempScan = (); my $NumberOfSpectra = Win32::OLE::Variant->new(VT_I4 | VT_BYREF, 0); $thermo_raw_file->GetNumSpectra($NumberOfSpectra); my $scan_num; for ($scan_num = 1; $scan_num <= $NumberOfSpectra; $scan_num++) { my $CurrentScanFilter = Variant(VT_BSTR | VT_BYREF); $thermo_raw_file->GetFilterForScanNum($scan_num, $CurrentScanFilter) +; if ($CurrentScanFilter =~ m/ms /) { my $pnScanNumber = Win32::OLE::Variant->new(VT_I4 | VT_BYREF, $sca +n_num); my $szFilter = Win32::OLE::Variant->new(VT_BSTR | VT_BYREF); my $nIntensityCutoffType = Win32::OLE::Variant->new(VT_I4 | VT_BYR +EF, 0); my $nIntensityCutoffValue = Win32::OLE::Variant->new(VT_I4 | VT_BY +REF, 0); my $nMaxNumberOfPeaks = Win32::OLE::Variant->new(VT_I4 | VT_BYREF, + 0); my $bCentroidResult = Win32::OLE::Variant->new(VT_BOOL, 0); my $pdCentroidPeakWidth = Win32::OLE::Variant->new(VT_R8 | VT_BYRE +F, 0); my $pvarMassList = Win32::OLE::Variant->new(VT_VARIANT | VT_BYREF) +; my $pvarPeakFlags = Win32::OLE::Variant->new(VT_VARIANT | VT_BYREF +); my $pnArraySize = Win32::OLE::Variant->new(VT_I4 | VT_BYREF, 0); $thermo_raw_file->GetMassListFromScanNum($pnScanNumber, $szFilter, + $nIntensityCutoffType, $nIntensityCutoffValue, $nMaxNumberOfPea +ks, $bCentroidResult, $pdCentroidPeakWidth, $pvarMassList, $pvarPeakFlags, $pnArraySize); @TempScan = @{$pvarMassList->Value()}; # undef @TempScan; does not clear memory # Need to deallocate $pvarMassList from memory # Help here!!!! print "Scan number: $scan_num Size: $#{$TempScan[0]}\n"; } } Win32::OLE->Uninitialize; print "Press any key to exit.\n"; <STDIN>; exit;

In reply to Memory Leak using Win32::OLE::Variant for a SafeArray passed by Reference by jwn

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.