Questions tagged [lazy-loading]

For programming questions about "lazy loading", a design pattern that defers initialization of an object until the point at which it is needed.

Lazy loading is a commonly used in computer programming to defer initialization of an object until the point at which it is needed. It can contribute to efficiency in the program's operation if properly and appropriately used. The opposite of lazy loading is Eager Loading.

5366 questions
40
votes
8 answers

Lazy module variables--can it be done?

I'm trying to find a way to lazily load a module-level variable. Specifically, I've written a tiny Python library to talk to iTunes, and I want to have a DOWNLOAD_FOLDER_PATH module variable. Unfortunately, iTunes won't tell you where its download…
wbg
  • 1,044
  • 1
  • 8
  • 18
39
votes
9 answers

How to solve the "Double-Checked Locking is Broken" Declaration in Java?

I want to implement lazy initialization for multithreading in Java. I have some code of the sort: class Foo { private Helper helper = null; public Helper getHelper() { if (helper == null) { Helper h; …
monsieurBelbo
  • 667
  • 1
  • 7
  • 15
39
votes
7 answers

Hibernate/Spring: failed to lazily initialize - no session or session was closed

For an answer scroll down to the end of this... The basic problem is the same as asked multiple time. I have a simple program with two POJOs Event and User - where a user can have multiple events. @Entity @Table public class Event { private Long…
Niko
  • 5,753
  • 2
  • 33
  • 48
39
votes
4 answers

Why not to use Spring's OpenEntityManagerInViewFilter

While a lot of posts have been written on the subject of Spring's OpenSession/EntityManagerInViewFilter, I couldn't find any that mentions its flaws. From what I understand, and assuming a typical layered web application architecture using a…
user186427
37
votes
4 answers

Entity Framework: I set the foreign key, SaveChanges then access the navigation property, but it doesn't load the related entity. Why not?

I am using this Entity class with Entity Framework 5 Code First: public class Survey { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ID { get; set; } public string SurveyName { get; set; } [Required] public…
Colin
  • 21,132
  • 15
  • 96
  • 179
36
votes
5 answers

Show activity Indicator while loading a lazy loaded Module in Angular 2

My scenario is as follows. I have a menu, with multiple options. Each menu should be shown depending on user permissions (already solved), most menu items are encapsulated as modules, and most of the modules are lazy loaded, so when a user clicks a…
vicmac
  • 565
  • 1
  • 5
  • 10
36
votes
3 answers

Eager , Lazy and explicit loading in EF6

I have read this tutorial and this article but I don't understand exactly the use of each loading type. I Explain I have this POCO : public partial class dpc_gestion { public dpc_gestion() { this.ass_reunion_participant = new…
Lamloumi Afif
  • 8,129
  • 23
  • 79
  • 175
36
votes
9 answers

C++ const getter method with lazy initialization

What is the proper way to implement a getter method for a lazily-initialized member variable and maintain const-correctness? That is, I would like to have my getter method be const, because after the first time it is used, it's a normal getter…
Dave Mateer
  • 16,802
  • 15
  • 90
  • 142
36
votes
3 answers

What is the use of the Hibernate @LazyCollection annotation

I have 2 entities as Parent and Child as OneToMany relation as @Entity public class Parent { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; private String name; @OneToMany(mappedBy = "parent", fetch =…
Rahul Agrawal
  • 8,583
  • 16
  • 42
  • 59
35
votes
1 answer

Can I add to an existing lazy database in R without having to recreate everything?

I created a database "mydb" that when run with lazyLoad("mydb") import in the workspace the (big) data.frames X and Y. I created "mydb" putting X and Y in an environment e and using the command tools:::makeLazyLoadDB(e,"mydb") Now I created a third…
lucacerone
  • 8,140
  • 12
  • 48
  • 72
34
votes
9 answers

Is there any way to detect when a CSS file has been fully loaded?

I've been testing a lot of lazy-loaders for JavaScript and CSS that insert