Re: Garbage Collection
From: Bill McCarthy
Date: 03/30/04
- Next message: Kalle: "very new to vb"
- Previous message: Herfried K. Wagner [MVP]: "Re: Combobox - ReadOnly"
- In reply to: Michael Hart: "Garbage Collection"
- Next in thread: Michael Hart: "Re: Garbage Collection"
- Reply: Michael Hart: "Re: Garbage Collection"
- Reply: Cor: "Re: Garbage Collection"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 30 Mar 2004 19:43:52 +1000
Hi Michael,
If you can explicitly call Dispose, it is always best to do this as this
provides timely release of resources the object may be holding onto. If you
don't call Dispose, the GC will eventually collect them for you once they go out
of scope, but that may take some time, and system resources could get low if any
of the objects waiting to be collected are holding onto resources, such as
bitmaps, brushes, fonts, or just large objects that take up large amounts of
memory.
So, the general rule is if you can safely call IDisposable.Dispose on the
object, then do so.
HTH's
Bill.
"Michael Hart" <me-donotspam@bigpond.net.au> wrote in message
news:%23Sv84ojFEHA.3456@tk2msftngp13.phx.gbl...
> I have a form that creates new objects in all sorts of fashion using vb.net.
>
> Some are created when the form opens with
>
> Private varName as new Object()
>
> just near the form class
>
> In some subs I have
>
> Sub Internal1()
> Dim myVar as new Object()
> End Sub
>
> in the declaration section
>
> and also sometimes I have the constructer separate to the declaration
>
> Sub Internal2()
> Dim newVar as Object
>
> newVar = new Object(parm1, parm2)
> End Sub
>
> Do I need to explicitly dispose of these objects or will the garbage
> collector [if there is one] take care of it when they go out of scope?
>
> When I do a Me.Close on a form does it invoke the garbage collector on the
> form?
>
>
>
>
>
>
- Next message: Kalle: "very new to vb"
- Previous message: Herfried K. Wagner [MVP]: "Re: Combobox - ReadOnly"
- In reply to: Michael Hart: "Garbage Collection"
- Next in thread: Michael Hart: "Re: Garbage Collection"
- Reply: Michael Hart: "Re: Garbage Collection"
- Reply: Cor: "Re: Garbage Collection"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|