minimize usage memory of program

Byak@

Active Member
Licensed User
i'm read about .Net and memory and find interesting code
B4X:
Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        AddHandler Application.Idle, AddressOf FlushMemory
    End Sub

    Private Sub FlushMemory()
        If System.Environment.OSVersion.Platform = PlatformID.Win32NT Then
            SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1)
        End If
    End Sub
    
    <DllImport("kernel32.dll")> _
    Public Shared Function SetProcessWorkingSetSize(ByVal handle As IntPtr, ByVal minimumWorkingSetSize As Integer, ByVal maximumWorkingSetSize As Integer) As Boolean
    End Function
this work on Desctop only and set a working set of program to min

how use it on b4ppc?
 

Byak@

Active Member
Licensed User
Andrew, as i know .Net allocate a "working set" in memory (when program start) and size of this set bigger than needed (for future) (and if we have many RAM this set bigger).
this code must change a working set to minimum needed.
for example our program have only one form and button,showed msgbox. but in memory this program use (!) 12mb in virtual memory (i have 2gb RAM) and it's working set 9mb!
as i'm understand with code,posted by me our program must use only ~1mb
 

agraham

Expert
Licensed User
Longtime User
Don't worry about it. The memory is allocated virtual memory, it does not mean that any actual physical RAM is mapped to it. If the OS does come under memory pressure then the Framework can surrender unused memory back to the OS. Just leave it to OS and the Framework to look after memory, that's what they are designed to do efficiently.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…