Saturday, April 19, 2014

Singleton vs. Transient

In the context of an IoC container (see http://docs.castleproject.org/Default.aspx?Page=LifeStyles&NS=Windsor&AspxAutoDetectCookieSupport=1) singleton is created once and reused for injection to dependent components when needed. Transient dependencies are created anew each time they are injected. Transient objects are released when the dependent object is released unless the dependent object is the root of the graph (the root of the graph is not managed by the container), i.e. Resolved explicitely -- in which case the transient must be Released explicitely or face potential memory leaks.

The transient keyword in the context of Java indicates to the writeObject method of the ObjectOutputStream that the field should not be considered part of the object state and thus not serialized.

No comments:

Post a Comment