Windows - Ram Cleaner-VBForums
Results 1 to 2 of 2

Thread: Windows - Ram Cleaner

  1. #1

    Thread Starter
    Addicted Member sinner0636's Avatar
    Join Date
    Sep 2009
    Posts
    232

    Windows - Ram Cleaner

    hello
    i am building a ram cleaner would anyone know how to get the memory size of each processes that was cleaned so i can get the total size that was cleaned?

    Code:
        Declare Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal process As IntPtr, ByVal minimumWorkingSetSize As Integer, ByVal maximumWorkingSetSize As Integer) As Integer
    
        Public Sub FlushRAM()
            Try
                GC.Collect()
                GC.WaitForPendingFinalizers()
    
                If (Environment.OSVersion.Platform = PlatformID.Win32NT) Then
                    SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
    
                    For Each p As Process In Process.GetProcesses()
    
                        'Get each process name 
                        Dim myProcesses As Process() = Process.GetProcessesByName(p.ProcessName)
    
                        For Each myProcess As Process In myProcesses
                          'Clean each process
                            SetProcessWorkingSetSize(myProcess.Handle, -1, -1)
                        Next myProcess
                    Next
                End If
    
            Catch ex As Exception
                'Call ExceptionLog(ex.StackTrace, ex)
            End Try
        End Sub
    Last edited by sinner0636; Jan 26th, 2018 at 03:48 PM.

  2. #2
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,451

    Re: Windows - Ram Cleaner

    This won't work, and in general "RAM cleaners" are snake oil.

    When a program is operating in Windows, it uses some amount of RAM. If Windows starts running low on RAM, it opts to move some of the things it has in RAM to disk in a special location called the "swap file". Generally, it tries to put "idle" bits of memory into the swap file. If the program needs to use stuff that got moved to the swap file, Windows has to figure out how to make enough room in RAM for it (by putting more thigns in the swap file) then moving the stuff back to RAM. It's slow to move things back and forth, so you really want to avoid too many "swaps".

    SetProcessWorkingSetSize() with the parameters you have chosen tells Windows, "Move as much as you can to the swap file and, from now on, try your hardest not to let this program use more RAM than is left over." That will make the "working set" go down, and definitely free up some RAM. But this happens at the cost of dramatically increasing the odds you will perform many swaps in the future, so overall system performance will go down.

    Free RAM is wasted money. It means your system COULD BE doing some things for you, but isn't. Windows is already very, very good at managing memory when programs behave themselves. Using this function in this manner gets in the way and means Windows can't be as effective.

    When programs don't behave themselves, there's no solution but to get the owner to fix it. This isn't going to magically fix memory leaks, it'll just slowly fill the swap file with garbage and degrade system performance.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width