473,387 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Static Member DTOR!!

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
Nov 17 '05 #1
4 1634
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
"Vai2000" wrote:
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

Nov 17 '05 #2
> 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.

TIA

Nov 17 '05 #3
public class Foo:IDisposable
{
public void Dispose(){glbArr.Clear();}
}

Is that OK?

TIA
"Daniel Jin" <Da*******@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.com...
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.

TIA

Nov 17 '05 #4
Vai2000 <no****@microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Naren | last post by:
Hello Grp, Correct me if I am wrong. static member functions can act only on static member varaibles.It can accessed by using the name of the class. Then why is there an access controller. ...
30
by: Joost Ronkes Agerbeek | last post by:
Why is it allowed in C++ to call a static member function of an object through an instance of that object? Is it just convenience? tia, Joost Ronkes Agerbeek
11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
8
by: SJ | last post by:
Hi: I have a class which has a static member function. The function implements something common to all instances. How can the static member function know all of the (Get access to the instances'...
8
by: Srini | last post by:
Hello all, I was just wondering about this. A const member function guarantees constness of the object within the function body. But there's no way for a member function to guarantee the...
11
by: ziman137 | last post by:
Hi all, I have a question here. What is the rationale behind ISO C++ for Static Member Definition? * ISO C++ forbids in-class definition/initialization of non-constant static member...
14
by: Dave Booker | last post by:
It looks like the language is trying to prevent me from doing this sort of thing. Nevertheless, the following compiles, and I'd like to know why it doesn't work the way it should: public class...
10
by: shanknbake | last post by:
I'm getting the following compile-time error: error C2352: 'Person::getCount' : illegal call of non-static member function Here is my getCount function declaration:...
6
by: VSP | last post by:
Hello, I am just implementing singleton pattern in various ways. In one implementation I created a static member and returning that static member in the getInstance() function. I have made...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.