Static Member DTOR!!

  • Thread starter Thread starter Vai2000
  • Start date Start date
V

Vai2000

Hi All I have a class with static data members in it. How do I un-initialize
them ? Looks like if static member is called repeatedly it has residual
memory from the last call. the member here is an Array. In other words how
do I ensure Destruction of the static members in the Class?
~Foo(){ glbArr.Clear();} this what I have thought of implementing.... Any
suggestions are welcome.

TIA
 
Hi,

I think there is design problem there, if you use a static class the purpose
is to serve not based on instances, so if you use resources you create and
dispose on the same method if they are not shared. That's why you can't
implement IDispose interface, the static class is on the heap.

In the only scenario that is valid a creation/destruction is when you have a
shared resource that needs to be disposed, in this case you should create
your own dispose method.

Hope this helps
Salva
 
Hi All I have a class with static data members in it. How do I un-initialize
them ? Looks like if static member is called repeatedly it has residual
memory from the last call. the member here is an Array.

if you find this to be a problem, then you need to rethink your design.
"static" obviously is not what you are looking for.
In other words how
do I ensure Destruction of the static members in the Class?
~Foo(){ glbArr.Clear();} this what I have thought of implementing.... Any
suggestions are welcome.

..NET doesn't have destructors, only finalizers, which is expressed in C#
using C like destructor syntax. there should be plenty of resources on the
web explaining why you should not implement it the way you did, along with
when's a right time to implement one, and how to go about doing it. you can
google for it.

hope it helps.
 
Vai2000 said:
public class Foo:IDisposable
{
public void Dispose(){glbArr.Clear();}
}

Is that OK?

Not if glbArr is a static variable. I mean, it'll *work*, but it's a
horrible way of doing things - it looks like it's doing something to
the object (being an instance method) but it's actually doing something
independent of any instances.
 
Back
Top