Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7983995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:07:40+00:00 2026-06-04T11:07:40+00:00

In C# 3.5 in a class I have a few static methods with some

  • 0

In C# 3.5 in a class I have a few static methods with some variables. Static methods are initialized first even if I do not initialize the class.

So are the variables inside the static methods also initialized in the beginning and not garbage collected ?

I want to know – will the memory be allocated for such method-variables even if I do not call the method or I call the method once and the method exits ? Or every time the method is called and it exits – the variables inside a method are garbage collected ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:07:41+00:00Added an answer on June 4, 2026 at 11:07 am

    Static methods are initialized first

    no, static methods aren’t “initialized” as such; they are (in standard implementations) JITted on first usage, but that is unrelated to memory allocations.

    So are the variables inside the static methods also initialized in the beginning and not garbage collected ?

    method variables are per call (on the stack) – not globally; the stack space is assigned as you enter the method. If you have reference-type variables, they will go out of scope when the method exits (assuming those variables aren’t “captured” into a delegate or lambda expression that lives longer that the method).

    Only objects are garbage collected; not variables. Reference-type variables just hold a reference to the object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a static class with a few methods that just take in a
I have a few static util methods in my project, some of them just
I have a few classes as shown here public class TrueFalseQuestion implements Question{ static{
I am using eclipse checkstyle plugin. I have few methods in a class A
I have 3 classes: an interface class that defines a few methods 2 classes
I have an interface based class that I want to have a few static
I have a class that basically has two methods the first one takes a
I have few buttons of which each button is assigned a class with a
I have few models - User , Teacher and TeacherLeader . class User <
I have a few labels on my page with a class of 'error', the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.