<p>What is Lazy Loading?</p>

<p>[Edit after reading a few answers]
Why do people use this term so often? </p>

<p>Say you just use a ASP/ADO recordset and load it with data or ADO.NET Datasource for a gridview.</p>

<p>I guess I should have asked why people use the term Lazy Loading, what "other" types are their?</p>

[{'answer_id': 36276, 'author': 'Kevin Goff', 'author_id': 1940, 'author_profile': 'https://Stackoverflow.com/users/1940', 'pm_score': 3, 'selected': False, 'text': '<p>wikipedia\'s  Definition\nLazy loading is a design pattern commonly used in computer programming to defer initialization of an object until the point at which it is needed. ...</p>\n\n<p><a href="http://en.wikipedia.org/wiki/Lazy%20loading" rel="noreferrer">http://en.wikipedia.org/wiki/Lazy%20loading</a></p>\n'}, {'answer_id': 36285, 'author': 'Javache', 'author_id': 1074, 'author_profile': 'https://Stackoverflow.com/users/1074', 'pm_score': 5, 'selected': False, 'text': '<p>Lazy Loading is a programming practice in which you only load or initialize an object when you first need it. This can potentially give you a big performance boost, especially if you have a lot of components in your application.</p>\n\n<p>As usual, <a href="http://en.wikipedia.org/wiki/Lazy_loading" rel="noreferrer">Wikipedia</a> has more details.</p>\n'}, {'answer_id': 36291, 'author': 'Eli Courtwright', 'author_id': 1694, 'author_profile': 'https://Stackoverflow.com/users/1694', 'pm_score': 3, 'selected': False, 'text': '<p>Here\'s an example from some actual Python code I wrote:</p>\n\n<pre><code>class Item(Model):\n    ...\n    @property\n    def total(self):\n        if not hasattr(self, "_total"):\n            self._total = self.quantity \\\n                  + sum(bi.quantity for bi in self.borroweditem_set.all())\n        return self._total\n</code></pre>\n\n<p>Basically, I have an Item class which represents an item in our inventory.  The total number of items we have is the number that we own plus the sum of all of the items that we\'re borrowing from various sources.  These numbers are all stored in our database, and it would be pointless to calculate this until the total is actually requested (since often Items will be used without the total being requested).</p>\n\n<p>So the total property checks whether the _total field exists.  If it doesn\'t, then the property code queries the database and computes it, then stores the value in the _total field so that it need not be recomputed the next time it\'s requested.</p>\n'}, {'answer_id': 36297, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 9, 'selected': True, 'text': "<p>It's called lazy loading because, like a lazy person, you are putting off doing something you don't want to.  The opposite is Eager Loading, where you load something right away, long before you need it.</p>\n\n<p>If you are curious why people might use lazy loading, consider an application that takes a LOOOOONG time to start.  This application is probably doing a lot of eager loading... loading things from disk, and doing calculations and whatnot long before it is ever needed.</p>\n\n<p>Compare this to lazy loading, the application would start much faster, but then the first time you need to do something that requires some long running load, there may be a slight pause while it is loaded for the first time.  Thus, with lazy loading, you are amortizing the load time throughout the course of running your application... and you may actually save from loading things that the user may never intend to use.</p>\n"}, {'answer_id': 36366, 'author': 'Mendelt', 'author_id': 3320, 'author_profile': 'https://Stackoverflow.com/users/3320', 'pm_score': 3, 'selected': False, 'text': '<p>The term lazy loading is usually used when talking about object relational mappers. If you use ADO.NET directly you always get eager loading (ie it always loads just what you specify).</p>\n\n<p>OR-mappers like nHibernate support returning proxy objects that get "filled in" with the right data only when you access the data. That way you only load the data that you really use. This is a usefull feature when you specify a lot of relations between objects that can get loaded from the database, you don\'t want the OR-mapper to load all the related objects and the objects related to the related objects and so on. That can result in your whole database getting loaded.</p>\n\n<p>This problem can be prevented by carefull design of your object model too. (using aggregates and only loading aggregate roots like in domain driven design is a way to get around this without using lazy loading).</p>\n\n<p>Lazy loading can result in the or mapper doing lots of small database accesses instead of retrieving all the data you need once. This can result in performance problems too.</p>\n'}, {'answer_id': 1162530, 'author': 'Pasan Indeewara', 'author_id': 111693, 'author_profile': 'https://Stackoverflow.com/users/111693', 'pm_score': 2, 'selected': False, 'text': "<p>is a Design pattern.</p>\n\n<p>Lazy loading: Untill your code require some operation done by a particular object, object is not initilaized, and once it's initialized it doesn't re-initialize the object but uses the previously initialized object.</p>\n\n<p>This makes your code much more efficient and helps managing memory usage.</p>\n\n<p>Example Applications of Lazy loading:</p>\n\n<p>Ghost\nLazy initialization\nValue holder</p>\n"}, {'answer_id': 1162566, 'author': 'Dan Rosenstark', 'author_id': 8047, 'author_profile': 'https://Stackoverflow.com/users/8047', 'pm_score': 2, 'selected': False, 'text': '<p>Lazy loading: you don\'t waste your time (nor your memory) with stuff you might not need. Then when you need it, it takes longer, but that\'s fine. </p>\n\n<p>Example from life: instead of actually learning that French phrasebook, you learn the phrases one at a time, as they\'re needed. When does this make sense? If you\'re only going to be in France for a short time (i.e., you won\'t need a lot of the phrases) or if you need to leave very soon. If you\'re there for two years and/or you have a long time to study, then it might be much more efficient to just learn the whole phrasebook up front (eager loading).</p>\n\n<p>[Inspired by the <a href="http://web.mac.com/scifione/orig/CHEM-HELP/MISC/atom-by-Venus.htm" rel="nofollow noreferrer">Atom as taught in gang terms by Venus on WKRP</a>.]</p>\n'}, {'answer_id': 1280993, 'author': 'Cyril Gupta', 'author_id': 33052, 'author_profile': 'https://Stackoverflow.com/users/33052', 'pm_score': 2, 'selected': False, 'text': "<p>Lazy loading is a term frequently used in databases to refer to the concept of loading parts of the required info only when it's needed.</p>\n\n<p>I.e. suppose you needed to have a record which has a join of several tables. If you fetched it all at once it would take longer than if you would fetch say only the main table. Using lazy-loading the rest of the information will be fetched only if it is needed. So it is actually 'efficient-loading' in certain scenarios.</p>\n\n<p>The other types of 'loading' is:</p>\n\n<ol>\n<li>Eager Loading - Loading all the connected tables at once.</li>\n</ol>\n"}, {'answer_id': 1670264, 'author': 'Philip Wallace', 'author_id': 190145, 'author_profile': 'https://Stackoverflow.com/users/190145', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/dd642331(VS.100).aspx" rel="nofollow noreferrer"><code>Lazy&lt;T&gt;</code></a> is now part of c# 4.0 - there is a nice page on <a href="http://msdn.microsoft.com/en-us/library/dd997286(VS.100).aspx" rel="nofollow noreferrer">MSDN</a> which explains the concept.</p>\n'}, {'answer_id': 9455987, 'author': 'd48', 'author_id': 391048, 'author_profile': 'https://Stackoverflow.com/users/391048', 'pm_score': 2, 'selected': False, 'text': "<p>An example of Lazy Loading would be a grid or table with lots of data on a webpage to view where the application only loads what the users browser viewpoint size is at that time. When they scroll down to want to view more content or data, more data would be loaded into view at that moment.</p>\n\n<p>This is becoming more of a common visual/interaction design pattern as well via ajax or jQuery.</p>\n\n<p>And as mentioned above, opposite would be Eager Loading where you don't take client into consideration thus potentially having a performance hit.</p>\n"}, {'answer_id': 18798757, 'author': 'Shivprasad Koirala', 'author_id': 993672, 'author_profile': 'https://Stackoverflow.com/users/993672', 'pm_score': 4, 'selected': False, 'text': '<p>Lazy loading is a concept where we delay the loading of the object unit the point where we need it. Putting in simple words on demand object loading rather than loading the objects unnecessarily. For instance if you have a "Customer" class which has "Orders" object aggregated. So you like to load the customer data but the orders objects you would like to delay until your application needs it. </p>\n\n<p>Below is a youtube video  which demonstrates how to use lazy loading , how we can implement lazy loading and advantages and disadvantages of the same.</p>\n\n<p><a href="http://www.youtube.com/watch?v=2SrfdAkwmFo" rel="noreferrer">http://www.youtube.com/watch?v=2SrfdAkwmFo</a></p>\n'}, {'answer_id': 35146184, 'author': 'Gideon Balaganesan', 'author_id': 4297347, 'author_profile': 'https://Stackoverflow.com/users/4297347', 'pm_score': 2, 'selected': False, 'text': '<p>Some of the advantages of lazy loading:</p>\n\n<ol>\n<li>Minimizes start up time of the application.</li>\n<li>Application consumes less memory because of on-demand loading.</li>\n<li>Unnecessary request to server is avoided.</li>\n</ol>\n'}, {'answer_id': 52690832, 'author': 'Rohit Katiyar', 'author_id': 6064724, 'author_profile': 'https://Stackoverflow.com/users/6064724', 'pm_score': 0, 'selected': False, 'text': '<p>According to geeksforgeeks,  Lazy loading is a software design pattern where the initialization of an object occurs only when it is actually needed and not before to preserve the simplicity of usage and improve performance.</p>\n\n<p><a href="https://www.geeksforgeeks.org/lazy-loading-design-pattern/" rel="nofollow noreferrer">https://www.geeksforgeeks.org/lazy-loading-design-pattern/</a></p>\n'}]
['https://Stackoverflow.com/questions/36274', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3747/']