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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:37:11+00:00 2026-05-15T16:37:11+00:00

Exactly what happens when Foo.SomeCheck() is called in the Bar class? Is an instance

  • 0

Exactly what happens when Foo.SomeCheck() is called in the Bar class? Is an instance of Foo created in order to call SomeCheck()? If so, is this instance stored on the heap, and is it ever collected through garbage collection?

public class Foo() {
    public static bool SomeCheck() {
        return true;
    }
}

public class Bar() {
    public void SomeMethod() {
        // what happens when we access Foo to call SomeCheck?
        if (Foo.SomeCheck()) {
            //do something
        }
    }
}
  • 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-15T16:37:11+00:00Added an answer on May 15, 2026 at 4:37 pm

    Static methods differ from instance methods in that no instance of the class they belong to needs to have been created for them to be called. When you call a static method, you in fact make the call using the name of the type rather than an instance of the type – which should reinforce the idea that static methods are not called on instances. That bears repeating and emphasis: No instance of a class is required to call a public static method of that class.

    Now, your example is malformed, but presumably, the line: if( Foo.SomeCheck() ) is calling the SomeCheck static method using the name of the type: Foo – not an instance. Bar however, has to be instantiated in order to make this call – however, in your example, you don’t have a well-formed instance of Bar. Code generally has to exist inside a method (or a member initializer) – which you don’t have here.

    To respond to the other parts of your question. Assuming the code in question is part of an instance method, something has to instantiate Bar – and invoke that method. That something would have to create or otherwise acquire an instance of Bar. Reference types will always be creted on the heap – but that’s largely irrelevant here.

    As for garbage collection, you normally shouldn’t worry about this. The .NET runtime makes sure to cleanup instances that are not referenced from any root object in your program. Roots are typically instances that reside somewhere on the callstack or are referenced by static members of one type or another. Since we don’t see any code here that creates or references Bar it’s impossible to say when it will be collected. For instance, if Bar is a singleton and stored somewhere in a static variable, it may live for a very long time – perhaps the entire lifetime of the program. You can’t really know without seeing all of the code that manipulates and manages Bar.

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

Sidebar

Related Questions

If I wrote an operator == for class Foo (in C++), what happens, exactly?
I hope this is programming-related enough. What exactly happens during the shutdown process of
What exactly happens when I call Session.flush() on an open hibernate session? Are all
What is E+3 ? What exactly happens here? Can we use this approach in
In plain Ruby, this works just fine: class TestSuper def foo puts In TestSuper.foo
If i have something like this : function foo(class){ for(i=0; i<(class.length);i++){ return document.getElementsByClassName(class)[i]; }
i'd like to know what exactly happens when i use reflection to call a
What exactly happens when you create a new instance using : Base b =
What exactly happens when I do this...? NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL urlWithString:@...]];
Inspired by this question , I was trying to find out what exactly happens

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.