|
-
Jul 6th, 2002, 11:06 AM
#1
Thread Starter
Fanatic Member
Disposing an array of classes
I have a class written that I instantiate into an array (one dimension) that is constantly Redimensioned.
When I exit the program, how do I properly dispose of every entity? Do I loop through all the elements in the array and dispose each one, or can I just use
ReDim MyArray(0)
MyArray(0).Dispose
(assuming that ReDim will automatically dispose array elements 1, 2, etc... when I shorten the array)
TIA
-C
-
Jul 6th, 2002, 12:57 PM
#2
It is my understanding that when the array goes out of scope, the objects will be scheduled for garbage collection. So even if you don't dispose them, the garbage collector will do so when it is convienent for it to do so. Most of the time when you call the dispose method for an object, it just tells the garbage collector to schedule it, but doesn't mean that the resources will be free that instant. The resources will get free when the garbage collector needs to free them or has free time to free them.
Now, if you are going to be using a LOT of resources with this array, and later, in the same method (same scope), your going to use a lot more resources, then I would call the dispose method. This way the garbage collector can free the resources of the array before it gets to the other part of your method that uses a lot of resources. Hope that makes sense.
As far as your question goes, I would loop through and dispose each one.
-
Jul 7th, 2002, 09:46 AM
#3
Thread Starter
Fanatic Member
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|