When should I use Lazy?

You typically use it when you want to instantiate something the first time its actually used. This delays the cost of creating it till if/when it’s needed instead of always incurring the cost. Usually this is preferable when the object may or may not be used and the cost of constructing it is non-trivial.

What’s so bad about Lazy I/O?

Lazy IO has the problem that releasing whatever resource you have acquired is somewhat unpredictable, as it depends on how your program consumes the data — its “demand pattern”. Once your program drops the last reference to the resource, the GC will eventually run and release that resource. Lazy streams are a very convenient style … Read more

Haskell foldl’ poor performance with (++)

There is much confusion about this issue. The usual reason given is that “repeatedly appending at end of list requires repeated traversals of list and is thus O(n^2)“. But it would only be so simple under strict evaluation. Under lazy evaluation everything is supposed to be delayed, so it begs the question whether there actually … Read more

hibernate: LazyInitializationException: could not initialize proxy

The problem is that you are trying to access a collection in an object that is detached. You need to re-attach the object before accessing the collection to the current session. You can do that through session.update(object); Using lazy=false is not a good solution because you are throwing away the Lazy Initialization feature of hibernate. … Read more