Re: Trouble of GDI+ generic error!



Hi Steven,

I still have something not quite sure about when I should call Dispose. The
followings are some pseudo code to show my question:


Public Shared Sub A()

Dim objFont As Font

objFont = New Font (...)

Call B (objFont)

' I should call objFont.Dispose here before end of the sub, right?

Call B (New Font (...))

' if I call sub B in this way (without creating a variable), how can I
call Dispose?

End Sub


Public Shared Sub B(ByVal objFont As Font)

'... do something here with objFont

' Do I need to call objFont.Dispose here before end of the sub?

' I'm not quite sure that objFont in this sub is an independent instance
from objFont in Sub A

End Sub


And you may right that I use a lot of font objects to print and this may be
the major cause of my problem.

Thanks again for your help!

Regards,
James Wong


"Steven Cheng[MSFT]" <stcheng@xxxxxxxxxxxxxxxxxxxx> ¼¶¼g©ó¶l¥ó·s»D:Nc%23lgPUbHHA.2256@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi James,

For those graphics objects such as Brush, Bitmap, Font... they will hold
win32 unmanaged resource handle, thus, whenever you have used large number
of such objects and haven't explcitly dispose them at ealiear time,
they'll
hold significant operating system resource(GDI handles). Therefore, you're
recommended to explicitly dispose them after finishing use them.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no
rights.



.



Relevant Pages

  • Re: Finalize and database connection... contradiction in msdn or a
    ... > | The Garbage Collector might do its stuff a number of times before ... > | sometime after LongRunningProcedure returns and the End Sub is executed ... > of when to Call Dispose, actually its now a list of when its OK not to ... > | Private Sub AAA ...
    (microsoft.public.dotnet.languages.vb)
  • Re: where can I find the symbol for the word "therefore"?
    ... Is it the decimal equivalent of the Unicode hex number? ... Sub GetLong() ... When I simply type 2234 and press ALT+x (without first selecting a font) ...
    (microsoft.public.word.docmanagement)
  • Re: Form does not see mouse events!!!!
    ... font size used as the buttons caption, ... Private WindowBorder As Long ... Private MinWindowWidth As Long ... Private Sub Form_Load ...
    (microsoft.public.vb.general.discussion)
  • Re: Finalize and database connection... contradiction in msdn or a
    ... of when to Call Dispose, actually its now a list of when its OK not to call ... | Factors like, the scope of an object, how long the life of an object is, ... | Private Sub AAA ... |>> ' Obtain a handle to an unmanaged resource ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Finalize and database connection... contradiction in msdn or a
    ... Factors like, the scope of an object, how long the life of an object is, how ... Private Sub AAA ... Widget class implements the IDisposable interface, is to call its Dispose ... >> If your database connection object uses any unmanaged resources then it ...
    (microsoft.public.dotnet.languages.vb)

Loading