473,378 Members | 1,500 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,378 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 1669
"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
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.