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 6156225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:34:24+00:00 2026-05-23T20:34:24+00:00

Most of the book never talk about how a program execute and how memory

  • 0

Most of the book never talk about how a program execute and how memory is allocated for them on stack and heap. when data stored on stack and when on heap.

Suppose i have one regular class like

public class MyClass
{
    int Age=0;
    string strName="None"
    Double Salary=0;

    public void Data1()
    {
        Age=30;
        strName="Robin";
        Salary=3500;
    }
}

Question

1) so for the above class how memory will be allocated. when program run the memory will be allocated or when we create instance then memory will be allocated. when we call Data1() through instance then what happen and how memory will be allocated. memory will be allocated for function call or for data member initialization? tell me how much memory will be allocated for age, name and salary. memory will be allocated on stack or heap.

public class MyClass
{
    static int y=0; 
    static string strComp="None"
    int Age=0;
    string strName="None"
    Double Salary=0;

    public void Data1()
    {
        Age=30;
        strName="Robin";
        Salary=3500;
    }

    public static void Data3()
    {
         y=50;
         strComp="Hello";
    }
}

2) how and when memory is allocated for static data member and function. when we call like
MyClass.Data3() then memory will be allocated or when we just run the apps. memory is allocated on heap or stack?

3) how memroy is allocated for static class. static class stored on heap or stack…if stack then why?

here i asked asked couple of question please explain in detail. thanks.

  • 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-05-23T20:34:25+00:00Added an answer on May 23, 2026 at 8:34 pm

    1.) Memory will be allocated when you create an instance of the class. When you call Data1() no additional memory is needed as you are only referencing fields of the class instance (and no other local variables). Since MyClass is a reference type, memory will be allocated on the managed heap.

    2.) Static methods do not consume any memory. Static fields are initialized before you access any static field or create any instance of the type they are contained in (MyClass in this case)

    3.) You cannot create an instance of a static class so no memory is allocated dynamically, only when the type itself is created. Static classes are guaranteed to be loaded and to have their fields initialized and their static constructor called before the class is referenced for the first time in your program. Once created a static class remains in memory until your application domain is shut down.

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

Sidebar

Related Questions

most of the books about Project Management (if not all of them) describe management
Most of time we represent concepts which can never be less than 0. For
Most program languages have some kind of exception handling; some languages have return codes,
Most people say never throw an exception out of a destructor - doing so
I just got a book that goes over all the VS2010 tools. Most I
After reading the most excellent book Head First Design Patterns, I began proselytizing to
I'm going through a book on Java and I've been understanding most of it
I think most would be surprised about the topic again, However I am referring
What's the best and most efficient book to learn JavaScript?
In most of the book we read that cluster index is the physical order

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.