Results 1 to 12 of 12

Thread: VB: Using statement still uses too much memory - Solved

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    VB: Using statement still uses too much memory - Solved

    Hi!
    I guess I must still be a newbie at this.

    So, I'm making a game which heavily uses graphics. I heard that the Using statement is supposed to dispose all resources from that element when it reaches End Using. However in Debug mode, the memory still rises to a scary amount (1 GB) before automatically disposing resources.
    Would it be more efficient, or more risky, or just plain stupid to call GC.Collect() every frame of the game? Does GC remove all unnecessary resources from all parts of the program, or just in that Sub, or .VB file?

    Anyway, here's an example of my code:

    Code:
        Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    
            Dim Screen_W As Int32 = 6
            Dim Screen_H As Int32 = 6
    
            Dim srcR As New Rectangle(0, 0, Screen_W * 24, Screen_H * 24)
    
            Dim B As New Bitmap(Screen_W * 24, Screen_H * 24)
    
            Using G As Graphics = Graphics.FromImage(B)
                Select Case Lv
                    Case Level.Lv1
                        ' G.DrawImage ... (a lot)
                    Case Level.Lv2
                        ' G.DrawImage ... (a lot)
                End Select
            End Using
    
            e.Graphics.DrawImage(B, ClientRectangle, srcR, GraphicsUnit.Pixel)
    
        End Sub
    (Form1_Paint happens very frequently.)

    Thanks in advance for the help!
    ~Nic
    Last edited by NinjaNic; Sep 13th, 2016 at 10:52 PM.

Tags for this Thread

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