ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
jvjason van clark30/07/2013

So, you may have noticed that SolidWorks 2013 is now doing some strange things when it comes to 'keeping models in memory' even if you close all of the files you have open.  It seems like SWX doesn't quite let everything go, resulting in strange warnings when you open more files ('File xxxx is already opened, whould like to use this already opened file?, file references magically pointing to the wrong folders, etc).  In addition, ever notice how SWX just takes a lot of memory to run?  Well, here's a little code that takes care of these issues:

Private Sub flushmemory()

        Try

            GC.Collect()

            GC.WaitForPendingFinalizers()

            If (System.Environment.OSVersion.Platform = PlatformID.Win32NT) Then

Dim myProcesses As Process() = Process.GetProcessesByName("SLDWORKS")

Dim myProcess As Process

For Each myProcess In myProcesses

SetProcessWorkingSetSize(myProcess.Handle, -1, -1)

Next

            End If

        Catch ex As Exception

        End Try

    End Sub

    Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As Boolean

    Function sldOnIdle() As Integer

        If openDocs.Count = 0 AndAlso idleFlag Then

            Dim workDir As String = iSwApp.GetCurrentWorkingDirectory()

idleFlag = False

flushmemory()

iSwApp.SetCurrentWorkingDirectory(workDir)

        End If

    End Function


Note that I have this code in an add-in that is always 'listening' to solidworks, so you would have to add the appropriate handlers, etc.  But, this takes care of the 'files in memory' problems and also make solidworks a little less memory-intensive

Enjoy!

Jason