Results 1 to 9 of 9

Thread: out of memory?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908

    out of memory?

    i got an error when i run an app. half way...:An unhandled exception of type 'System.Out of memory Exeception' occured in mscorlib.dll

    wat happen? i a pc of 512 k ram

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    What happened was you ran out of memory. I could write some code that would devour your available memory in two seconds, and hold it for ransom while it begged for mercy.

    Sorry I couldn't be more specific about the error, but you didn't post any additional info about the error, like where it occured, or such.

    Usually these errors happen when you do not properly dispose of images, release system resources (fonts, brushes)... etc...etc..

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908
    yesh you are right!....the error occurs in the codes where i have placed images on every form of my app....like:
    Me.images...=GetObject(...images..)...(sorry i didnt remember the codes clearly cuz i am posting this forum at home while the work is done in my office )
    ....bascially how do i properly dispose of images, release system resources (fonts, brushes)... etc...etc..?
    and i thing o note that the portion where errors occurs is not in my 'written codes' ..thanks you!
    Last edited by Goh; Apr 23rd, 2004 at 07:44 PM.

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. myImage.Dispose

    will probably solve ur problems. You will have to recheck your code and be sure you not missing a few of these.

    As far as forms, same thing applies, dispose of them when they are not needed.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908
    why do i need to dispose images that in.net? i dun do that in vb6...where do i dispose the images? and furthermore i have put labels with big fonts on it..do i need to resize the font also?

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You have to dispose of the image explicity, because they consume much resources, for some reason, it is the proper way, it kinda tags it for disposal as soon as possible.

    Resizing is easier under .Net, but it still can never be a non-issue. There are many things left to consider, and frankly, I haven't worked with Windows Forms applications in over 5 months (moved to internet dev), and you really need to start a new thread for a question about fonts.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908
    wow thanks for for information....can i conclude that whenever i switch from one form1 to another form2..i would first have to dispose the images on the form1....etc....am i right?

  8. #8
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Once you are done with an image, you should dispose of it. Without seeing your code, its hard to tell you what to do.

    As an example, use a 2mb image file for this test.

    Start a new windows application, throw a button on the form.
    Double-click the button and throw the below code in the button_click event.

    Change myFile to the full path and filename of your test image file. Remember it should be 2mb or more to see the results clearly.

    Now build and run your app.

    Open up Task Manager (ctrl-alt-del), and under Processes, look for WindowApplication1 or whatever the new project ends up being called.

    Now click the button on your form about 20 times as fast as you want.

    You should see the memory usage jump dramatically. Now, go back and uncomment the block of code that is initially commented out, and rerun the test.

    You will see it jumps, but always recovers to a manageable level.


    VB Code:
    1. Dim fs As New IO.FileStream("F:\Joy's Wedding\IMG_3563.jpg", IO.FileMode.Open)
    2.         Dim s As Image = Image.FromStream(fs)
    3.         Dim r As Image = Image.FromStream(fs)
    4.         Dim t As Image = Image.FromStream(fs)
    5.         Dim g As Image = Image.FromStream(fs)
    6.         Dim x As Image = Image.FromStream(fs)
    7.         Dim h As Image = Image.FromStream(fs)
    8.         fs.Close()
    9.  
    10.         '''keep this block commented out for first test
    11.         's.Dispose()
    12.         'r.Dispose()
    13.         't.Dispose()
    14.         'g.Dispose()
    15.         'x.Dispose()
    16.         'h.Dispose()
    17.         ''''''''''''''''

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908
    hm...but i did not hard codeto put the image on the form initially...i put the image in IDE....that means i have to dispose the image when the next form is shown?

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