Out of memory exception

  • Thread starter Thread starter Crirus
  • Start date Start date
C

Crirus

I have 3 user controls of mine, combined in the same container user
control...
This one is hosted in a form... yesterday I was lack of hard disk space and
got a out of memory exception because of lots of page faults my control
need... But I'm not sure where to put a try -catch in my application.. the
out of memory occured after lots of resize and repaints.. I tested how
control draw themselfs together... Should I use try catch on Me.Refresh
calls of any of does controls?
 
* "Crirus said:
I have 3 user controls of mine, combined in the same container user
control...
This one is hosted in a form... yesterday I was lack of hard disk space and
got a out of memory exception because of lots of page faults my control
need... But I'm not sure where to put a try -catch in my application.. the
out of memory occured after lots of resize and repaints.. I tested how
control draw themselfs together... Should I use try catch on Me.Refresh
calls of any of does controls?

Maybe you don't dispose some objects and this causes the exception.
Post some drawing code you use.
 
Is not that.. I take care of any Brush, Pen, Font object I use... I have
the habit to write a dispose as soon as I dim such objects in order to avoid
forgetting
Is hard to post code.. is too big, and I'm sure you will not have patient to
follow it...
 
If I do this in a init images function

tmp = New Bitmap(imgAutoShadow(i, j))
tmp.RotateFlip(RotateFlipType.RotateNoneFlipX)
imgAutoShadow(7, j) = tmp

Do I have to call tmp.dispose()?

If I use it will dispose the image or only the reference to image because I
still have one reference in imgAutoShadow?
I dont want to dispose the image becasue I need it later
 
One more question: I found a graphics created in a function to draw somthing
on a bitmap that I forgot to dispose..
:)
(the routine was writen before I got the habit mentioned)

What is the drawback if I forget such things?
 
* "Crirus said:
One more question: I found a graphics created in a function to draw somthing
on a bitmap that I forgot to dispose..
:)
(the routine was writen before I got the habit mentioned)

What is the drawback if I forget such things?

It can cause a "memory leak", your application may run out of memory...
 
* "Crirus said:
If I do this in a init images function

tmp = New Bitmap(imgAutoShadow(i, j))
tmp.RotateFlip(RotateFlipType.RotateNoneFlipX)
imgAutoShadow(7, j) = tmp

Do I have to call tmp.dispose()?

No. You are still using the bitmap in 'imtAutoShadow(7, j)'.
If I use it will dispose the image or only the reference to image because I
still have one reference in imgAutoShadow?

You cannot "dispose" the reference. 'Dispose' will dispose the /object/
the reference is pointing to.
I dont want to dispose the image becasue I need it later

ACK.
 
* "Crirus said:
Hmm, And I thought GC is a very good thing on memory management... I guess
is only good :)

It's very good, but it's better to dispose objects to clear unmanaged
resources directly when you don't need the object any more.
 
Back
Top