How to destroy arrays

S

Scott M.

So then, would this make sense:

Sub Foo
Dim x as new FooFoo()
x.stuff()
'Done using x now, but don't want to wait for dispose to naturally run
x.dispose()

...some operation that will take time...
...some operation that will take time...
...some operation that will take time...
...some operation that will take time...

End Sub


Now, in this case, if there were clean up code in x's dispose method we
could control when it happens, rather than waiting for the GC to get around
to it?

-Scott
 
J

Jon Skeet [C# MVP]

Scott M. said:
So then, would this make sense:

Sub Foo
Dim x as new FooFoo()
x.stuff()
'Done using x now, but don't want to wait for dispose to naturally run
x.dispose()

...some operation that will take time...
...some operation that will take time...
...some operation that will take time...
...some operation that will take time...

End Sub

Yup. (Assuming that FooFoo implements IDisposable, of course.)

If you don't call Dispose yourself, it could be a *very* long time
before resources are cleaned up - especially if the object is in
generation 2 (very unlikely in this case, but speaking about a more
general situation).
Now, in this case, if there were clean up code in x's dispose method we
could control when it happens, rather than waiting for the GC to get around
to it?

Yes. IDisposable should only be implemented for types either directly
containing unmanaged resources (handles etc) or for types which wrap
other types implementing IDisposable (eg StreamWriter, which wraps a
Stream).
 
S

Scott M.

Ok Joh, thanks.

-Scott


Jon Skeet said:
Yup. (Assuming that FooFoo implements IDisposable, of course.)

If you don't call Dispose yourself, it could be a *very* long time
before resources are cleaned up - especially if the object is in
generation 2 (very unlikely in this case, but speaking about a more
general situation).


Yes. IDisposable should only be implemented for types either directly
containing unmanaged resources (handles etc) or for types which wrap
other types implementing IDisposable (eg StreamWriter, which wraps a
Stream).
 
C

Cor Ligthert

Hi Scott,

Have a look at these pages, it has lot information about the GC and
describes it in my opinion very clear.

It as well describe dispose, however I saw in these newsgroups that the idea
about it is turning (also by Microsoft people), it is telling the old way
which even says that you have (when you follow the text) to dispose
everything by code that has a dispose method. Every control by instance has
it, however in my opinion is the dispose of that done by the component
class, which the control implements. About the dispose I have in general
probably the same idea as Jon now.

(In addition, please do not catch me on a word; in such a small message, not
everything is right)

However the pages are great, I got the link from Jay B. Harlow

http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnpag/html/scalenet.asp

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

Top