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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:55:59+00:00 2026-05-26T04:55:59+00:00

I lazy load all my members. I have been doing this for a while

  • 0

I lazy load all my members. I have been doing this for a while and simply taken lazy load to be a good thing at face value.

Let’s say we have

public class SomeClass
{
   public int anInt;
   public SomeReferenceType member1;

   public SomeClass()
   {
      //initialize members in constructor when needed (lazy load)
      anInt = new int();
      member1 = new SomeReferenceType();
   }
}

Are there any disadvantages to doing things this way? Is this a proper lazy load pattern? Does it make sense to lazy load a value type (with modern RAM does it even matter)?


After what I have learned from your answers, I would like to know if there is any difference between the above and this…

public class SomeClass
    {
       public int anInt;
       public SomeReferenceType member1 = new SomeReferenceType();

       public SomeClass()
       {

       }
    }
  • 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-26T04:56:00+00:00Added an answer on May 26, 2026 at 4:56 am

    First of all, initializing a member inside the constructor isn’t lazy loading.

    Lazy Loading is initializing the member the first time it is requested. A simple example in .NET (with some double-check locking so we don’t have threading issues):

    public class SomeClass
    {
        private object _lockObj = new object();
        private SomeReferenceType _someProperty;
    
        public SomeReferenceType SomeProperty
        {
            get
            {
                if(_someProperty== null)
                {
                    lock(_lockObj)
                    {
                        if(_someProperty== null)
                        {
                            _someProperty= new SomeReferenceType();
                        }
                    }
                }
                return _someProperty;
            }
            set { _someProperty = value; }
        }
    }
    

    Luckily, if you’re using .NET 4, you can now user the Lazy<T> Class which handles the issues for you and makes things a lot easier.

    Second of all, lazy loading is a good idea when you have many members that could be costly to load and you’re sure that you’re going to be using all of those values. That cost would cause the type to be un-necessarily slow to instantiate.

    Lazy Loading just for the sake of lazy loading is adding unnecessary complexity to your code and could cause issues down the road if done improperly (when dealing with threading, for example).

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

Sidebar

Related Questions

Problem: I am having trouble implementing a recursive image lazy load in all relevant
I am using lazy load jquery plugin . It tells me to put this
I have X sections. I want to lazy load images in different Custom Cell
I'm trying to lazy load options into a select with jquery. This code works
I am using jQuery Lazy Load to load thumbnails on a page I have
I know there are plugins to lazy load images. I have a coupon code
I'm referring to this popular marked answer: Lazy load of images in ListView Perhaps,
Is there a way to make a multiple level lazy load? If I have
I want to lazy load of @Lob properties. First ,i use javassist to instrument
Does SubSonic 2.2 support lazy loading? Can I lazy load a property of an

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.