Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / April 2005

Tip: Looking for answers? Try searching our database.

Static Variables during Garbage Collection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
saurabhgarg2k@gmail.com - 05 Apr 2005 16:00 GMT
Hi there,

I was just wondering that when an object's finalized method is called,
garbage collector must have marked it as garbage and unreachable even
though i am accessing the Static Variables of the Class after finalized
method is called.

So the doubt is whether the object is really been deallocated and if
yes how can i still access the static variable of the Class, ya i know
Static variables are irrelevant to the instance of a class, they are
shared but they are also consuming some memory and has to be released,
so wats the story behind Static Variables, firstly how are they
allocated in the managed heap and secondly how and when they are
deallocated.

Looking forward to a reply

Thanks and Regards
Saurabh Garg
Manoj G [MVP] - 05 Apr 2005 16:27 GMT
Saurabh,

Do not see static members as something that are allocated or collected in a
special way, different from normal objects. You can very well make a static
member eligible for a collection by setting it to null (provided that there
are no other references to the same object). If left untouched, a static
member would last for the life of the appdomain in which it lies.

HTH,
Manoj G
[MVP ,  Visual Developer - Visual Basic ]
http://msmvps.com/manoj/

> Hi there,
>
[quoted text clipped - 15 lines]
> Thanks and Regards
> Saurabh Garg
Kikalo - 06 Apr 2005 07:53 GMT
The GC considers static reference types to be roots.

Cumps,
RM

> Hi there,
>
[quoted text clipped - 15 lines]
> Thanks and Regards
> Saurabh Garg
Willy Denoyette [MVP] - 06 Apr 2005 22:28 GMT
> Hi there,
>
[quoted text clipped - 15 lines]
> Thanks and Regards
> Saurabh Garg

Static variables aren't released, the objects they are pointing at will
become eligible for GC when set to null (Nothing in VB). The static fields
themself are dropped when the AD unloads.

Willy.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.