Results 1 to 4 of 4

Thread: How to Reduce Process Memory? *Solved*

  1. #1

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    How to Reduce Process Memory? *Solved*

    Hey, I've been trying to make a game using pure VB, and obviously one must use many graphics objects. This is just test code, but still, when I debug the program, the memory still goes up to 600-700MB. Graphics objects are created and used very fast as you can see. How can I reduce this? Do I need to dispose of them after being used?

    Thanks!

    ~Nic

    vb Code:
    1. Public Class Form1
    2.  
    3.     Dim DefaultImg As New Bitmap(My.Resources.TestImg)
    4.     Dim T1 As New Timer() With {.Interval = 10, .Enabled = True}
    5.  
    6.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    7.         DoubleBuffered = True
    8.         AddHandler T1.Tick, AddressOf T1_Tick
    9.     End Sub
    10.  
    11.     Private Function LotOfCode() As Bitmap
    12.         Dim Bmp As New Bitmap(800, 600)
    13.         Dim G As Graphics = Graphics.FromImage(Bmp)
    14.         G.DrawImage(DefaultImg, -5, -5)
    15.         G.FillRectangle(Brushes.Red, 5, 5, 15, 15)
    16.         Return Bmp
    17.     End Function
    18.  
    19.     Private Sub T1_Tick()
    20.         Invalidate()
    21.     End Sub
    22.  
    23.     Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    24.         e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
    25.         Dim TestImg As Bitmap = LotOfCode()
    26.         Dim ImgPt As New Point(25, 25)
    27.         e.Graphics.DrawImage(TestImg, ImgPt)
    28.     End Sub
    29.  
    30. End Class
    Last edited by NinjaNic; Feb 21st, 2016 at 01:08 AM.

  2. #2

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: How to Reduce Process Memory?

    Here's some more info: My real game/program/thing actually gets up to 2 GB before it crashes. (That's the max limit for debugging, right?) And there's also a lot of math used repeatedly, but I wouldn't expect that to be a problem. I just read about the "Using" statement, so I tried it out in my test program but it didn't change anything, unless I did it wrong. Is it common, or even preferred to use Graphics in a "Using" block?

    Thanks.

  3. #3

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: How to Reduce Process Memory? *Solved*

    Solution:
    Put all the code into Form1_Paint's sub procedure. It speeds up the app by a lot, plus it doesn't use much memory. I'm not sure why.

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

    Re: How to Reduce Process Memory? *Solved*

    Whatever caused it is in your real code, that example doesn't have anything that should cause additional memory usage or slowdown. It's likely there's some difference between your example and the real code that didn't show through.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

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