By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,360 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,360 IT Pros & Developers. It's quick & easy.

ArrayLists and Dispose

P: n/a
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
Share this Question
Share on Google+
7 Replies

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.