Disposing all objects
-
I am creating a program in VB.net (VS2005) I want to know that how to dispose all objects used in my program while closing the program. Thanks. Gagan
You enumerate through your objects and call Dispose on them. Seriously, your question about shutting down is not answerable because we have no idea what your code is doing, how the app is written, what your code does in the event of a shutdown request, ... What is the main purpose of the app and how is the engine that provides this functionality written??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
I am creating a program in VB.net (VS2005) I want to know that how to dispose all objects used in my program while closing the program. Thanks. Gagan
Some objects have a .Dispose method which you can call. Also, you can set the object to "nothing", which will indicate to the garbage collector that the object is no longer referenced. For example: myObj.dispose() ' only if supported myObj = nothing ' indicate that the object is no longer referenced
-
Some objects have a .Dispose method which you can call. Also, you can set the object to "nothing", which will indicate to the garbage collector that the object is no longer referenced. For example: myObj.dispose() ' only if supported myObj = nothing ' indicate that the object is no longer referenced
David Mujica wrote:
Also, you can set the object to "nothing", which will indicate to the garbage collector that the object is no longer referenced.
that is completely irrelevant when the app is about to shut down as the OP stated. :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
-
I am creating a program in VB.net (VS2005) I want to know that how to dispose all objects used in my program while closing the program. Thanks. Gagan
When an app shuts down, the Operating System recovers memory allotted to that app. So you don't have to worry about it. Modern operating systems (including Windows) are pre-emptive, i.e., they don't need the permission or co-operation of the applications to recover memory.
-
When an app shuts down, the Operating System recovers memory allotted to that app. So you don't have to worry about it. Modern operating systems (including Windows) are pre-emptive, i.e., they don't need the permission or co-operation of the applications to recover memory.
Also, all .Net finalizers are run while the application shuts down.
-
Also, all .Net finalizers are run while the application shuts down.