jwn has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Memory Leak using Win32::OLE::Variant for a SafeArray passed by Reference
by Anonymous Monk on Jun 20, 2014 at 07:27 UTC | |
by jwn (Initiate) on Jun 20, 2014 at 16:24 UTC | |
by Anonymous Monk on Jun 22, 2014 at 08:20 UTC | |
by Anonymous Monk on Jun 24, 2014 at 05:57 UTC | |
by Anonymous Monk on Jun 24, 2014 at 07:39 UTC |