If you have to print multiple instances of a (seemingly any) form (with different parameters, order number, invoice number) using the COM AccpacReport and AccpacReportSetup types they leak a lot of memory.
In the space of 200 iterations there is about a 100MB leak -> 500KB per report.
Attempting to print any more than 2400 invoices (for example) in a single loop will eventually blow up the address limit of a 32-bit process.
Below is a demonstration - Moving the ReportSelect, the Set ... = Nothings, Rpt.ReInit inside, out of the loops does nothing.
My conclusion is the AccpacReport object is the culprit and there's nothing I can do.
To make matters worse we've tried to identify the issue leak using WinDbg, but there seems to be a debug in WinDbg (outstanding since September...thanks Microsoft) preventing us from obtaining the stack of the one of leaks.
Dim rpt As AccpacCOMAPI.AccpacReport Dim rptPrintSetup As AccpacCOMAPI.AccpacPrintSetup Set rpt = ReportSelect("OECONF01[OECONF01.RPT]", " ", " ") Set rptPrintSetup = GetPrintSetup(" ", " ") rptPrintSetup.DeviceName = "Microsoft Print to PDF" rptPrintSetup.OutputName = "PORTPROMPT:" rptPrintSetup.Orientation = 1 rptPrintSetup.PaperSize = 9 rptPrintSetup.PaperSource = 15 rpt.PrinterSetup rptPrintSetup For l = 1 To 200 rpt.ReInit ' Tried this this, tried without rpt.SetParam "PRINTED", "1" ' Report parameter: 4 rpt.SetParam "SERIALLOTNUMBERS", "0" ' Report parameter: 10 rpt.SetParam "QTYDEC", "0" ' Report parameter: 5 - O/E Sales History:Detail,Sort by Item Number rpt.SetParam "SORTFROM", "ORD000000037168" ' Report parameter: 2 rpt.SetParam "SORTTO", "ORD000000037168" ' Report parameter: 3 rpt.SetParam "SWDELMETHOD", "3" ' Report parameter: 6 rpt.SetParam "PRINTKIT", "0" ' Report parameter: 7 rpt.SetParam "PRINTBOM", "0" ' Report parameter: 8 - O/E Picking Slips rpt.SetParam "SWPRINTONHOLD", "0" ' Report parameter: 9 rpt.SetParam "@SELECTION_CRITERIA", "(NOT(ISNULL({OEORDH.ORDNUMBER}))) AND (({OEORDH.ORDNUMBER} >= ""ORD000000037168"") AND ({OEORDH.ORDNUMBER} <= ""ORD000000037168"")) AND ({OEORDH.ONHOLD} = 0) AND ({OEORDH.TYPE} <> 4) AND ((({OEORDH.COMPLETE} = 1) OR ({OEORDH.COMPLETE} = 2)) OR ((({OEORDH.COMPLETE} = 3) OR ({OEORDH.COMPLETE} = 4) OR ({OEORDH.COMPLETE} = 5)) AND ({OEORDD.COMPLETE} = 0)))" ' Report parameter: 0 rpt.NumOfCopies = 1 rpt.Destination = PD_FILE rpt.Format = PF_PDF rpt.PrintDir = "g:\temp\bad.pdf" rpt.PrintReport Next l Set rptPrintSetup = Nothing Set rpt = Nothing