Results 1 to 3 of 3

Thread: Your VB .NET App taking up too much memory??

  1. #1

    Thread Starter
    Hyperactive Member LeeSalter's Avatar
    Join Date
    Oct 2002
    Location
    Notts, England
    Posts
    307

    Your VB .NET App taking up too much memory??

    Use this to clean it up....very,very useful.

    VB Code:
    1. Public Class MemoryManagement
    2.  
    3.     Private Declare Function SetProcessWorkingSetSize Lib "kernel32.dll" ( _
    4.   ByVal process As IntPtr, _
    5.   ByVal minimumWorkingSetSize As Integer, _
    6.   ByVal maximumWorkingSetSize As Integer) As Integer
    7.  
    8.     Public Shared Sub FlushMemory()
    9.         GC.Collect()
    10.         GC.WaitForPendingFinalizers()
    11.         If (Environment.OSVersion.Platform = PlatformID.Win32NT) Then
    12.             SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
    13.         End If
    14.     End Sub
    15.  
    16. End Class

    I found the above on the net because my DataGrid driven application was simply taking up too much memory on the client pc's.

    I put this class into my project and call the FlushMemory function after each time a user fills a DataSet....my apps memory usage went from 30,000KB to less than 5,000KB!
    "I'm Brian and so is my Wife"

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Your VB .NET App taking up too much memory??

    Hi

    Calling SetProcessWorkingSetSize will force part of the memory used by the application will be written to disk, so performance will be affected.

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    Hyperactive Member LeeSalter's Avatar
    Join Date
    Oct 2002
    Location
    Notts, England
    Posts
    307

    Re: Your VB .NET App taking up too much memory??

    Hello!

    I didn't know that.
    However, the app that I'm writing, the users of it will have it open all day (and it dynamically updates data), so I needed to get around the problem of running out of virtual memory and this solution seems to work for me (they'll just run out of disk space now instead! )

    Maybe I'm just not freeing up my resources properly.
    "I'm Brian and so is my Wife"

Posting Permissions

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



Click Here to Expand Forum to Full Width