473,411 Members | 2,093 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,411 software developers and data experts.

Are Classes with Static State Ever Garbage Collected ??

I have a low level question . . .

If I have an assembly with a single class with a static int property, I know
the assembly will get loaded the first time the class is referenced. At that
point, I now have a "never been explicitly instantiated object" in memory
that can be accessed by all code that was built with a reference to the
assembly. Obviously, somewhere in the bowels of the system there is a
reference to this "never been explicitly instantiated object"

My question is, can this "object" ever get garbage collected since it came
into being without the need for "new" and there are no explicit references
that can be set to null ?? If not, then it must be destined to just waste
valuable address space until the process dies :*(

Thanks,

LES
Jul 22 '05 #1
4 1586
Hi,
Through out the runtime the CLR maintains a single instance of a static
class even without the need of new so the application space remains until
app terminates
best,
Subin Kushle
"Lester" <Le****@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com...
I have a low level question . . .

If I have an assembly with a single class with a static int property, I know the assembly will get loaded the first time the class is referenced. At that point, I now have a "never been explicitly instantiated object" in memory
that can be accessed by all code that was built with a reference to the
assembly. Obviously, somewhere in the bowels of the system there is a
reference to this "never been explicitly instantiated object"

My question is, can this "object" ever get garbage collected since it came
into being without the need for "new" and there are no explicit references
that can be set to null ?? If not, then it must be destined to just waste
valuable address space until the process dies :*(

Thanks,

LES

Jul 22 '05 #2
Hi,
Through out the runtime the CLR maintains a single instance of a static
class even without the need of new so the application space remains until
app terminates
best,
Subin Kushle
"Lester" <Le****@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com...
I have a low level question . . .

If I have an assembly with a single class with a static int property, I know the assembly will get loaded the first time the class is referenced. At that point, I now have a "never been explicitly instantiated object" in memory
that can be accessed by all code that was built with a reference to the
assembly. Obviously, somewhere in the bowels of the system there is a
reference to this "never been explicitly instantiated object"

My question is, can this "object" ever get garbage collected since it came
into being without the need for "new" and there are no explicit references
that can be set to null ?? If not, then it must be destined to just waste
valuable address space until the process dies :*(

Thanks,

LES

Jul 22 '05 #3
Hi,
Through out the runtime the CLR maintains a single instance of a static
class even without the need of new so the application space remains until
app terminates
best,
Subin Kushle
"Lester" <Le****@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com...
I have a low level question . . .

If I have an assembly with a single class with a static int property, I know the assembly will get loaded the first time the class is referenced. At that point, I now have a "never been explicitly instantiated object" in memory
that can be accessed by all code that was built with a reference to the
assembly. Obviously, somewhere in the bowels of the system there is a
reference to this "never been explicitly instantiated object"

My question is, can this "object" ever get garbage collected since it came
into being without the need for "new" and there are no explicit references
that can be set to null ?? If not, then it must be destined to just waste
valuable address space until the process dies :*(

Thanks,

LES


Jul 22 '05 #4
Lester <Le****@discussions.microsoft.com> wrote:
I have a low level question . . .

If I have an assembly with a single class with a static int property, I know
the assembly will get loaded the first time the class is referenced. At that
point, I now have a "never been explicitly instantiated object" in memory
that can be accessed by all code that was built with a reference to the
assembly. Obviously, somewhere in the bowels of the system there is a
reference to this "never been explicitly instantiated object"

My question is, can this "object" ever get garbage collected since it came
into being without the need for "new" and there are no explicit references
that can be set to null ?? If not, then it must be destined to just waste
valuable address space until the process dies :*(


Static members are only garbage collected when the AppDomain containing
them is garbage collected. I would seriously ask yourself just how much
memory is going to be "wasted" though - chances are it's not
significant.

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

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

Similar topics

3
by: Adam Smith | last post by:
Hi. I have a static arraylist in a class which is populated during the class's static constructor. Will this arraylist or the class objects allocated on it ever be garbage collected if I don't...
16
by: Ed Sutton | last post by:
I use a mutex to disallow starting a second application instance. This did not work in a release build until I made it static member of my MainForm class. In a debug build, first instance got...
1
by: Chris Bardon | last post by:
I'm working on a class library in .net, and am having a problem that I can only describe as a memory leak (which garbage collection was supposed to eliminate). My class library contains a single...
9
by: Joanna Carter \(TeamB\) | last post by:
Following on from the other discussion, I have to just check something out with reference to disposal of resources held in static fields. I have a Persistence Framework that is 'globally...
5
by: Frank | last post by:
Our system maintains session state using the ASP.NET State Server service. We expect some of our session state objects to be over 85K, which categorizes them to be VLO's (very large objects) in terms...
8
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical...
4
by: Lester | last post by:
I have a low level question . . . If I have an assembly with a single class with a static int property, I know the assembly will get loaded the first time the class is referenced. At that...
6
by: spacehopper_man | last post by:
I'm considering ditching all use of Session state in favour of Application state. This is because - from what I can work out - it will be more memory efficient for me. I have three questions:...
9
by: Chuck Cobb | last post by:
I am creating some static classes with static methods and static variables, but I have a question: What is the lifetime of static classes and static variables? Is there any risk that these...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.