• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 791
  • Last Modified:

vb.net dispose

I was curious is it necessary to use .dispose

for example
dataadapter.dispose
con.dispose


form1.dispose

what is the point, does it do anything????


0
bman9111
Asked:
bman9111
  • 2
2 Solutions
 
prairiedogCommented:
Som objects use very expensive resource, such as database connections, file handles, or system locks, so we might need to ensure that the resource is freed as soon as the objects are no longer in use.

The Dispose function will force the object to release the resource that has been allocated and to become unreferenced, then when the Garbage Collector starts working, the memory will be released back to availabe memory. If you don't call Dispose function, the Garbage Collector wil sonner or later release the memory, but it will take longer time to finish.
0
 
thenrichCommented:
To answer your question it's not really common practice to use the dispose method unless your really strapped for resources. As mentioned above the garbage collector will get it sooner or later
0
 
nachiketCommented:
thenrich i think Dispose() should be used. (it does not make sense only if u have no Unmanaged resources)

GC do not do the work of Dispose(). You MUST use dispose for all the unmanaged resources. infact you should use the same code in Finaliser also. so incase some developer forgot to use Dispose() atlease finaliser will take care. however usinf finaliser will make the GC slow and object will leave some extra GC cycles(depending on generation)

so allways us Dispose() and Finaliser() both and the MOST important thing is to remember to suppress finaliser from Dispose() so code does not get called 2 times.

read following question which answers the issue in great detail

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21385937.html
0
 
thenrichCommented:
Excellant point about using it for the unmanaged code. But again - Is there a lot of development with unmanaged code in VB .NET maybe in some cases but in general - no. For the most part it's just extra coding that doesn't need to be there.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now