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

  • Home
  • SEARCH
  • 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 8430049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:30:09+00:00 2026-06-10T05:30:09+00:00

lets take this example, which I think covers all my questions: class SomeClass {

  • 0

lets take this example, which I think covers all my questions:

class SomeClass
{
    static SomeType PropertyA
    {
        get
        {
            if (....)
                return MethodA();
            else
                return MethodB();
        }
    }

    static SomeType MethodA() { ... }
    static SomeType MethodB() { ... }
}

will calling a SomeClass.PropertyA property create a memory leak? My opinion is no, since the property itself doesn’t have a backing field, which would create a memory leak. I ask this because I have read that static properties can create memory leak, but I think it is the backing field that is responsible for memory leak, since it holds a reference to instance.

So in above example, MethodA, MethodB, and PropertyA in above example should not create any memory leaks. Am I wrong about this?

Another question I have is: I have lots of classes that mostly do not have a state nor data. They are just acting as a proxy. Some of those methods are called very frequently. My question would be: should I make those classes singleton, static, or regular classes?

Perfect example would be a class that contains 5-10 methods, and executes some SQL queries.

1) If I have them as regular, then I would need to create them very often (on some user reaction), call some method, and then allow the to be garbage collected.

2) choosing between singleton and static, what would be the pros / cons?

3) If I had a class that contains proxy methods, but has 2-3 IDbCommands that contains 10 parameters each, and is beneficial to reuse them, would that change anything in choosing the correct pattern?

Edit: since I got some answers that confused me more, probably due to misunderstanding, I am going to post an answer to my 1st question. I have done a test, where I allocated a large byte array (300MB), which is retrieved through PropertyA (and MethodA). Both PropertyA abd MethodA in above example will not hold a reference to this object, after fetching it, so as soon as calling code is done with array, it will be handled by GC. So in case where we use static property with getter only, or static methods, there should not be any memory leaks.

  • 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-10T05:30:10+00:00Added an answer on June 10, 2026 at 5:30 am

    So in above example, MethodA, MethodB, and PropertyA in above example should not create any memory leaks. Am I wrong about this?

    If you mean they won’t create or hold onto any memory, then that’s true – the property itself will not hold memory.

    Static fields do not create a “memory leak” – the type initializer for the type will be run prior to the first use of the class, and, if a field requires memory, the memory for that field will be allocated. This memory is not cleared – if that’s what you mean by a “leak” -but there is no instance to free, so this is expected and desired behavior.

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

Sidebar

Related Questions

Lets take stackoverflow as an example: Post Postid Title Mess -------------------------------------------------- 1 Title1 This
lets take for example i have a string declared: string master = 1.2.3.4; which
Take for example this table (let's call it BIN_TABLE ): +------+------+ | A |
I have a very basic question. Lets take this snippet: #include <stdio.h> void foo(void)
Is it possible to generate comments for closing div tags, lets take this ex.
Lets take qsort()'s comparison callback function as an example int (*compar)(const void *, const
I've asked a few questions which have touched around this issue, but I've been
Take this code for example: $('.photo').hover( function() { //display heading and caption $(this).children('div:first').stop(true,false).animate({top:0},{duration:200, easing:
EDIT To simplify this further. Let's take a look at this structure: Table1: idProduct
I'm creating an app that lets users take and store photos in a Core

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.