473,326 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Destroying objects

I am working on a VB.NET (2003) application and I am confused about object
lifetimes. I have a class of objects that are created in a manager class and
added to a collection in that class. I am not sure how to destroy an object
once it is no longer required as a part of the collection. In VB 6 I would
have assigned "nothing" to it. According to my extensive reading this is not
the way to go with VB.NET.

My objects are derived from "Object" as is my class that has the collection.
Will the objects be destroyed when the ref-count goes to zero?

All the objects only have managed resources allocated, so do I need to
implement a Dispose method?

Many thanks,
Sid.
Mar 21 '06 #1
3 1667
"Microsoft" <si*@nowhere.com> schrieb
I am working on a VB.NET (2003) application and I am confused about
object lifetimes. I have a class of objects that are created in a
What is a "class of objects"?
manager class and added to a collection in that class. I am not sure
how to destroy an object once it is no longer required as a part of
the collection. In VB 6 I would have assigned "nothing" to it.
In VB6 I would remove it from the collection. I'd do the same in VB.Net.
According to my extensive reading this is not the way to go with
VB.NET.
Why not?
My objects are derived from "Object" as is my class that has the
collection. Will the objects be destroyed when the ref-count goes to
zero?
There is no ref count. The garbage collector destroys all objects when they
are not reachable anymore, and when it "thinks" there is the time to do it
or whenever it is necessary.

All the objects only have managed resources allocated, so do I need
to implement a Dispose method?


No, unless the object created other objects that have a Dispose method and
holds references to them.
It's all explained here:
http://msdn.microsoft.com/library/en...management.asp

http://msdn.microsoft.com/library/en...collection.asp
Armin

Mar 21 '06 #2

"Microsoft" <si*@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
My objects are derived from "Object" as is my class that has the
collection. Will the objects be destroyed when the ref-count goes to zero?
No, they'll be destroyed when nothing is referencing them and Garbage
Collection can be bothered to get around to cleaning them up.
All the objects only have managed resources allocated, so do I need to
implement a Dispose method?


Probably not, no, but it's worth checking whether any of the classes
you're /using/ have a Dispose method - if so, you ought to call it (from
your
own).

HTH,
Phill W.
Mar 22 '06 #3
Thank you for the input,
Sid.

"Phill W." <p-***********@o-p-e-n.a-c.u-k> wrote in message
news:dv**********@yarrow.open.ac.uk...

"Microsoft" <si*@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
My objects are derived from "Object" as is my class that has the
collection. Will the objects be destroyed when the ref-count goes to
zero?


No, they'll be destroyed when nothing is referencing them and Garbage
Collection can be bothered to get around to cleaning them up.
All the objects only have managed resources allocated, so do I need to
implement a Dispose method?


Probably not, no, but it's worth checking whether any of the classes
you're /using/ have a Dispose method - if so, you ought to call it (from
your
own).

HTH,
Phill W.

Mar 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: TooN | last post by:
Hi, I'm building an application with over 10thousand database entries. I was wondering if it would be useful, regarding memory load and server performance to unset/destroy objects at the moment...
1
by: Roman S. Golubin1709176985 | last post by:
Hello everybody! I wrote an project with one class (Class) and two forms (Form1, Form2): -----------------------------------Form2AndClass1Begin---------------------- ------------------ public...
4
by: pachanga | last post by:
After you destroy a Object and its send to the garbage collections, can you retrieve the object back? Also, if you can, can you destroy an object permantly with no trace of it?
2
by: jaymtz78 | last post by:
Hi, I have a huge windows application that I'm working on and I'm completely baffled. Sometimes when I try to close the application, it won't let me! I have an Exit button in my menu bar that...
1
by: tilbyj | last post by:
Hello, I am new to .NET, and am trying to write an application that connects to a DCOM server that we use. Wonderfully (unlike with ASP) I can now import the type library for my DCOM server, and...
4
by: Olumide | last post by:
Hello - I have two classes A and B as follows: class B{ public: ~B(){ cout << "destroying B" << endl; } }; class A{
3
by: Bartholomew Simpson | last post by:
I am writing some C++ wrappers around some legacy C ones - more specifically, I am providing ctors, dtors and assignment operators for the C structs. I have a ton of existing C code that uses...
7
by: Markus Pitha | last post by:
Hello, I have a class Adjazenzmatrix with the following method and destructor: private: Adjazenzmatrix *wegmatrix; Adjazenzmatrix *distanzmatrix; ..
41
by: =?Utf-8?B?VGltIE1hcnNkZW4=?= | last post by:
Hi, I am after suggestions on the best practice declaring and destroying objects. some example code: Private Sub MySub Dim frmMyForm As MyForm Try
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.