What is lazy loading?
Loading
What is lazy loading?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Upamanyu Roy ChoudhuryPosted Feb 19, 2013, 12:07 PM
Lazy loading means not creating an object until the first time it is accessed.
Loook into the follwoing code snippet:
public class Example {
private Vector data = null;
public Vector getData() {
if (this.data == null) {
this.data = new Vector();
// Load data into vector …
}
return this.data;
}
}
This technique is most useful when you have large hierarchies of objects (such as a product catalog). You can lazy-load subordinate objects as you navigate down the hierarchy, and thereby only create objects when you need them.
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).
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.
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).
We can have this in Java,.Net
Read the follwoing links to get a clear overview
http://msdn.microsoft.com/en-us/library/vstudio/dd456846(v=vs.100).aspx
http://www.digital-web.com/articles/improve_page_performance_with_lazy_loading/
http://whatis.techtarget.com/definition/lazy-loading-dynamic-function-loading
Please mark it as answer if you find this post as helpful
Jignesh TrivediPosted Feb 19, 2013, 10:33 PM
hi,
The "Lazy Loading" design pattern actually equips the developer with the art of providing data only when a property is called for. In other words, it is a on-demand loading. It is an efficient technique to improve performance.
Lazy loading refers to creating and initializing of objects only when it is required for the first time. That means, you can define the object whenever you wish to, but it actually gets created only when you access its method/property/function.
please refer
http://wiki.asp.net/page.aspx/408/lazy-loading/
http://visualstudiomagazine.com/articles/2011/09/08/lazy-loading-in-net.aspx
hope this will help you.