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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:32:17+00:00 2026-05-25T12:32:17+00:00

Consider situation when we have a class with couple of static methods that use

  • 0

Consider situation when we have a class with couple of static methods that use one static object.

public class Person
{
    private static PresonActions actions = new PresonActions();

    public static void Walk()
    {
        actions.Walk();
    }
}

I know that the life cycle of static members in asp.net apps is equals to appdomain life cycle.
So this means that the object is not destroyed and the resources are not deallocated until I’ll restart the appdomain.

But if we will use a property to create an instance of class PresonActions each time something access it, will the object will be destroyed or not?

public class Person
{
    private static PresonActions actions { get { return new PresonActions(); } }

    public static void Walk()
    {
        actions.Walk();
    }
}

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-25T12:32:18+00:00Added an answer on May 25, 2026 at 12:32 pm

    Static variable continuouse allocation is an Evil. Keep an eye on your memory consuption, especially if you are talking about server side component (ASP.NET).

    To answer your question: GC collects when he can an object which none longer reference by anyone in application.

    Do not do this. It’s very easy jump into memory problems with this approach and after spend hours to profile and find memory leaks.

    If you want to change an object content, write a function that updates object content, without creating a new instance of it.

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

Sidebar

Related Questions

Consider the following situation: We have two Localizable.string files, one in en.lproj and one
Consider a situation. I have an in-proc COM server that contains two COM classes.
I have a class that is a manager sort of class. One of it's
Consider the following snippet: import java.util.*; public class EqualsOverload { public static void main(String[]
Consider a situation: I have a buffer of known length that presumably stores a
Consider the following situation: [Export] class A { } class B { [Import] private
Consider a situation. We have some specific C++ compiler, a specific set of compiler
I have an app that's about presenting fictional simplified cities. Please consider the following
Consider the following common situation: You have some MainView in your Cocoa application, loaded
In the code below, I have a while(true) loop. Consider a situation where there

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.