Results 1 to 2 of 2

Thread: Memory allocation is not released

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Question Memory allocation is not released

    Hi,

    I'm working with CF2.0 VB.NET 2005.

    I have an application running on PPC.
    The structure is as follows:
    1. startup form (main) has a button to open an other form
    2. form1 has a custom image button and normal button
    3. form2 had a custom image button and normal buttion

    for 2 and 3 the custombutton onclick switches between form1 and form2.
    Always disposing the previous form.
    So if I click on form1, he closes himself, raiseevent to the main form and from the main form I open form2. This is the same for form2.

    On form1 and form2 I paint a background image on the form.
    In my dispose of my forms I always dispose that image.

    If I run the windows CE remote performance monitor and monitor the memory load I have the following.

    Start app: memory load 38MB
    open form1: Jumps to 44MB
    open form2 from form1: go's to 45MB
    switching between to's two doesn't change in memory. Always 44MB and 45MB with sometimes a peak to 47MB and back to 45MB.
    Eventually closing the form1 or form2 and returning to the main form result's in the memory load staying at 44MB.
    My two forms are disposed and still it doesn't return to the 38MB initial load of the main form.

    Could somebody explain this to me or help me resolve this issue.

    The Code:

    Code:
    ' Main form
    Public Class main
    Public iCurrentForm As Integer = 1
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Me.Close()
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim frm As New Form1
            iCurrentForm = 1
            AddHandler frm.openNext, AddressOf openNext
            frm.Show()
            frm.BringToFront()
        End Sub
    
        Private Sub openNext()
            If iCurrentForm = 1 Then
                Dim frm As New Form2
                iCurrentForm = 2
                AddHandler frm.openNext, AddressOf openNext
                frm.Show()
                frm.BringToFront()
            Else
                Dim frm As New Form1
                iCurrentForm = 1
                AddHandler frm.openNext, AddressOf openNext
                frm.Show()
                frm.BringToFront()
            End If
        End Sub
    End Class
    
    ' Form1
    Imports D8D.PPC.iGuide.Resources.MyResources
    ' namespace has the images in them
    
    Public Class Form1
    
        Public Event openNext()
    
        Private _background As Bitmap
    
        Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
            If Not _background Is Nothing Then
                e.Graphics.DrawImage(_background, New Rectangle(0, 0, Me.Width, Me.Height), New Rectangle(0, 0, _background.Width, _background.Height), GraphicsUnit.Pixel)
            Else
                MyBase.OnPaintBackground(e)
            End If
        End Sub
    
        Public Sub New()
    
            ' This call is required by the Windows Form Designer.
            InitializeComponent()
    
            ' Add any initialization after the InitializeComponent() call.
            _background = Images.LoadBitmap("bkgBiografie")
            btnClose.ImageUp = Images.LoadBitmap("btnClose")
            btnClose.ImageDown = Images.LoadBitmap("btnClose_down")
        End Sub
    
        Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
            Me.Close()
            RaiseEvent openNext()
            Me.Dispose()
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Me.Close()
        End Sub
    
        Protected Overrides Sub Finalize()
            Dispose(False)
            MyBase.Finalize()
        End Sub
    
    End Class
    'form1 designer
    
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Public Class Form1
        Inherits System.Windows.Forms.Form
        Implements IDisposable
    
        Shadows disposed As Boolean = False
    
        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If Not Me.Disposed Then
                If disposing Then
                    If Not _background Is Nothing Then
                        _background.Dispose()
                        _background = Nothing
                    End If
                End If
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            End If
            Me.Disposed = True
            MyBase.Dispose(disposing)
        End Sub
    
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
    
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Me.btnClose = New D8D.PPC.Controls.UI.Buttons.ImageButton
            Me.Button1 = New System.Windows.Forms.Button
            Me.SuspendLayout()
            '
            'btnClose
            '
            Me.btnClose.Location = New System.Drawing.Point(67, 61)
            Me.btnClose.Name = "btnClose"
            Me.btnClose.Size = New System.Drawing.Size(352, 64)
            Me.btnClose.TabIndex = 0
            Me.btnClose.Text = "ImageButton1"
            '
            'Button1
            '
            Me.Button1.Location = New System.Drawing.Point(165, 336)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(144, 40)
            Me.Button1.TabIndex = 1
            Me.Button1.Text = "Button1"
            '
            'Form1
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(192.0!, 192.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi
            Me.ClientSize = New System.Drawing.Size(480, 640)
            Me.ControlBox = False
            Me.Controls.Add(Me.Button1)
            Me.Controls.Add(Me.btnClose)
            Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
            Me.Location = New System.Drawing.Point(0, 0)
            Me.MinimizeBox = False
            Me.Name = "Form1"
            Me.Text = "Form1"
            Me.TopMost = True
            Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
            Me.ResumeLayout(False)
    
        End Sub
        Friend WithEvents btnClose As D8D.PPC.Controls.UI.Buttons.ImageButton
        Friend WithEvents Button1 As System.Windows.Forms.Button
    
    End Class
    
    'form2 is the same as form1

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Memory allocation is not released

    Don't worry about it.

    That's the simple answer. When you get rid of an item, it isn't destroyed, and the memory isn't freed. All that happens is that it gets flagged for destruction. When the Garbage Collector runs, it will get destroyed at that point. As for memory, if the program needs more, it gets it from the OS pool. If the pool gets low, the OS can reclaim it, but unless the pool gets low, the OS won't bother.

    Edit: By the way, you might search in this forum for using panels. In my opinion, no CF program should have more than a single form unless the second form handles almost a different program (the one time I used two forms was for that case). Forms are just too slow, and, as you have noted, they have some memory overhead....not that that matters any.
    My usual boring signature: Nothing

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