473,507 Members | 6,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayLists and Dispose

I have an arraylist of class objects and the class contains unmanaged
resources. When I remove an item from the arraylist using the .remove or
..removeat method, will the object's dispose method be called automatically or
do I have to call it before removing it from the ArrayList?
--
Dennis in Houston
Nov 21 '05 #1
7 1787
On 2005-07-27, Dennis <De****@discussions.microsoft.com> wrote:
I have an arraylist of class objects and the class contains unmanaged
resources. When I remove an item from the arraylist using the .remove or
.removeat method, will the object's dispose method be called automatically or
do I have to call it before removing it from the ArrayList?


Nope... In this case, you might want your collection to be inherit from
System.Collections.CollectionBase. Then, in your subclass, override
it's OnRemoveComplete method.

--
Tom Shelton [MVP]
Nov 21 '05 #2
Ben
Hi, Tom. Is there a way to put a break point on dispose class (wherever that
is on the dotNET framework) to see whenever VB is calling it or not?

"Tom Shelton" wrote:
On 2005-07-27, Dennis <De****@discussions.microsoft.com> wrote:
I have an arraylist of class objects and the class contains unmanaged
resources. When I remove an item from the arraylist using the .remove or
.removeat method, will the object's dispose method be called automatically or
do I have to call it before removing it from the ArrayList?


Nope... In this case, you might want your collection to be inherit from
System.Collections.CollectionBase. Then, in your subclass, override
it's OnRemoveComplete method.

--
Tom Shelton [MVP]

Nov 21 '05 #3
On 2005-07-27, Ben <Be*@discussions.microsoft.com> wrote:
Hi, Tom. Is there a way to put a break point on dispose class (wherever that
is on the dotNET framework) to see whenever VB is calling it or not?


Well that depends... Dispose is a method of the IDisposable interface,
so if it's your class and you have implemented dispose, sure you can put
a break in it. If it isn't then that is a little more difficult :)

But, removing an object won't call dispose. You won't have the
reference any more, so it will get it's Finalize method called at the
next GC - but that's probably not what you want. Like I said, the
easiest way to do what you want is to create a class that inherits from
CollectionBase and then override it's OnRemoveComplete method.

--
Tom Shelton [MVP]
Nov 21 '05 #4
Dennis,

20% of the classes of dotnet implements directly IDisposable because of the
fact that they inherit from componentmodel, those are probably 80% of the
classes you normally use.

In those you don't normally have to worry about Dispose. (That is as well
the reason that those classes have a dispose method. The same as all classes
have a ToString and GetType method because all classes inherits from Object)
It is up to you if you use that GetType in your program.

http://msdn.microsoft.com/library/de...mberstopic.asp

I hope this helps,

Cor
Nov 21 '05 #5
Thanks for the answer. If I understand it correctly, I can just let Finalize
and GC to the work or implement my own arraylist class using the
CollectionBase Class as my base class if I have unmanaged resources to
dispose of.

--
Dennis in Houston
"Cor Ligthert [MVP]" wrote:
Dennis,

20% of the classes of dotnet implements directly IDisposable because of the
fact that they inherit from componentmodel, those are probably 80% of the
classes you normally use.

In those you don't normally have to worry about Dispose. (That is as well
the reason that those classes have a dispose method. The same as all classes
have a ToString and GetType method because all classes inherits from Object)
It is up to you if you use that GetType in your program.

http://msdn.microsoft.com/library/de...mberstopic.asp

I hope this helps,

Cor

Nov 21 '05 #6
On 2005-07-27, Dennis <De****@discussions.microsoft.com> wrote:
Thanks for the answer. If I understand it correctly, I can just let Finalize
and GC to the work or implement my own arraylist class using the
CollectionBase Class as my base class if I have unmanaged resources to
dispose of.


Pretty much...

--
Tom Shelton [MVP]
Nov 21 '05 #7
Dennis,

As addition, you can open a component instead of a class or a form.
You get than a complete template.

I hope this helps,

Cor
Nov 21 '05 #8

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

Similar topics

2
10032
by: Steven | last post by:
Hello, In my asp.net application, I have the MainForm.aspx.cs (where all the functions are defined) and ClasssificationInfo.cs class. This is the Classification Info class -- using System;...
1
2588
by: godsella | last post by:
First i have two stored procedures, i have passed the values of each one into two different arraylists of dates. how can i compare the two arraylists of dates? Thanks in advance
2
1338
by: Morten Hauge | last post by:
Hi! I have a problem, I'm not sure if this is the proper way to do it, but I have the following scenario: I want to list all categories, and all products in that category whenever I select a...
5
2384
by: drdave | last post by:
I would like to have ten arraylists created within a loop.. is there a conversion or something I can do to acheive this.. pseudo: Dim counter As Integer = 0 Dim ArrName As ArrayList ...
0
1223
by: steve | last post by:
I'm looking for a code example how to compare the values in a given record in different arraylists two arraylists, two fields in each record, both defined as string I'm thinking that it's...
3
3185
by: steve | last post by:
I need to compare the value of a field in a row on an arraylist with the value of a field on a second arraylist I have this bit of code working for arrays but cant get it working for arraylists The...
4
1675
by: Andy in S. Jersey | last post by:
I would like to create an unknown number of Arraylists, meaning, I don't know how many I should create until runtime. I will be reading a table, and 0,1,2, or more fields have to be put into...
1
1758
by: Newbie19 | last post by:
I'm just learning java arrays/arraylists and was wondering what are the best books for learning java arrays/arraylists? I know practice is the best way to learn, but I have a hard time...
3
2050
by: =?Utf-8?B?Sm9zaFA=?= | last post by:
Hi All, I am attempting to compare values in two arraylists to make sure all the values are the same. I am running into trouble with my code if both arraylists compare okay up until a point and I...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.