Memory

  • 14 years ago

    I just recently jumped from VB6 to VB.Net and I was wondering if VB still had the problem of hogging memory and not properly unloading all the forms?

    I tried googling for code to include in my applications but I did not come up with anything.

    I would greatly appreciate it if someone has the solution to this

  • 14 years ago

    Just Dispose of objects when you're done with them, don't declare more than you need, don't reference a library if you don't have to.  It's that simple Wink [;)].  Oh, and Task Manager doesn't really give you a very good picture of how much memory your application is actually using (or so I've heard).



  • 14 years ago
    Try to create some very large string and dispose it, do it in cycles and app will fall with not enough memory ... It wouldn't catch up with clearing memory... e.g.

    sub main()
    do
     call cs()
    loop
    end sub

    sub sc()
    dim x as string=space(100 000 000)
    x=nothing
    end sub

    Big Smile [:D] ... only joke, but it will really fall after few cycles














  • 14 years ago
    Haha, well my system wouldn't even do that once, no error, it just didn't do it.  I was thinking more along the lines of:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Dim i As Integer

          For i = 0 To 100
             Dim bmp As New Bitmap(10000, 10000)
             bmp.Dispose()

             Me.Text = i.ToString
             Application.DoEvents()
          Next

          MessageBox.Show("")
       End Sub











    This code actually runs, albeit slowly since it's allocating 10,000 x 10,000 x 3 (Width x Height x Bytes per Pixel) = 300,000,000 bytes of memory (about 286 megabytes).

    Long story short, you shouldn't have to worry about .NET and it's garbage collector.






Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An expert is a man who has made all the mistakes that can be made in a very narrow field” - Niels Bohr