473,388 Members | 1,230 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,388 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 1584
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: 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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.