ArrayLists and Dispose

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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.
 
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?
 
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.
 
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/d.../cpref/html/frlrfsystemobjectmemberstopic.asp

I hope this helps,

Cor
 
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.
 
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...
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top