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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:16:33+00:00 2026-06-10T18:16:33+00:00

Possible Duplicate: how can i find out how many objects are created of a

  • 0

Possible Duplicate:
how can i find out how many objects are created of a class in C#

Is it possible to get number of instances which is active(created and not yet destroyed) for selected class?

For example:

public class MyClass { }

...

var c1 = new MyClass();
var c2 = new MyClass();

count = GetActiveInstances(typeof(MyClass))

Should return 2. If GC destroy any of these classes then 1 or 0.

  • 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-10T18:16:35+00:00Added an answer on June 10, 2026 at 6:16 pm

    You can holds global static counter in your program.
    This is a simple thread safe solution:

    class MyClass
    {
        static int counter = 0;
    
        public MyClass()
        {
            Interlocked.Increment(ref counter);
        }
    
        ~MyClass()
        {
            Interlocked.Decrement(ref counter);
        }
    }
    

    also take a look at the following similar question – Count number of objects of class type within class method

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

Sidebar

Related Questions

Possible Duplicate: Find out which class called a method in another class. Hello everyone,
Possible Duplicate: Java Class.cast() vs. cast operator I am unsuccessfully trying to find out
Possible Duplicate: How do you find out the caller function in JavaScript? How can
Possible Duplicate: How can I find out what Page has installed my Facebook Canvas
Possible Duplicate: for x in y, type iteration in python. Can I find out
Possible Duplicate: Operator[][] overload I've looked on the internet but can't find a definitive
Possible Duplicate: Best way to find Browser type & version? In HTML/JavaScript, How can
Possible Duplicate: Can I run from command line program created by Eclipse? I am
Possible Duplicate: Can not connect to Oracle via VBA - Driver's SQLSetConnectAttr Failed I
Possible Duplicate: C/C++ line number Hi, I have a simple error manager class that

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.