batch saving of pdf's results in GDI handle depletion

hello,

RE: SW version = SW 2015 workgroup pdm

the macro below runs a batch save of all the drawings in a particular directory and saves in another directory.

unfortunately, running the macro results in a 'hanging' of SW after some 400 files.

the reason for that is depletion of the number of GDI handles/objects.

under normal circumstances, SW is using 1000 to 1500 GDI handles.

while the macro is running, the number of handles steadily creeps up to approx 9000 after some 400 files; SW becomes sluggish and finally hangs; requiring a restart.

this depletion of resources has been addressed in a blog:

forum.solidworks.com/community/administration/blog/2011/03

under the name:  System resources running low ? (a.k.a. GDI handle depletion)

according to the blog however, the issue should have been resolved in a SW 2011 update.

there is of course a second possibility:  a  coding error in the macro, which I haven't been able to detect.

could someone with similar experiences help me out here ?
many thanks,

Paul

'***************************************

Option Explicit

Sub main()

Dim swApp           As SldWorks.SldWorks

Dim swModel         As SldWorks.ModelDoc2

Dim swExportPDFData As SldWorks.ExportPdfData

Dim boolstatus      As Boolean

Dim longstatus      As Long

Dim longwarnings    As Long

Dim Part            As Object

Dim sFileName       As String

Dim sModelName      As String

Dim sPartName       As String

Dim nErrors         As Long

Dim nWarnings       As Long

Const PathSrc       As String = "Z:\solidworks\drawings\"

Const PathTgt       As String = "Z:\hotfolder\pdf\"

Const PathJpg       As String = "Z:\hotfolder\Thumbnails\"

'***************************************

On Error Resume Next

Set swApp = Application.SldWorks

sFileName = Dir(PathSrc & "*.slddrw")

swExportPDFData.ViewPdfAfterSaving = False

Do Until sFileName = ""

    Set swModel = swApp.OpenDoc6(PathSrc & sFileName, swDocDRAWING, swOpenDocOptions_Silent, "", longstatus, longwarnings)

    Set swModel = swApp.ActiveDoc

    sModelName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)

    sModelName = PathTgt & Left(sModelName, InStrRev(sModelName, ".") - 1) & ".PDF"

    Set swExportPDFData = swApp.GetExportFileData(1)

    swModel.ViewZoomtofit2

    swModel.ForceRebuild

    swModel.Extension.SaveAs(sModelName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, swExportPDFData, nErrors, nWarnings)

    If Not swModel Is Nothing Then

        swApp.CloseDoc swModel.GetTitle

    End If

    Set swModel = Nothing

    sFileName   = Dir

Loop

End Sub

'***************************************

SolidworksApi macros