Solved dispose

Posted on 2005-04-14
Last Modified: 2008-02-01
I was curious is it necessary to use .dispose

for example


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

Question by:bman9111
    LVL 22

    Accepted Solution

    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.
    LVL 5

    Expert Comment

    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
    LVL 4

    Assisted Solution

    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
    LVL 5

    Expert Comment

    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.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now