guice/Manual/Internals/ClassLoading

Class Loading

Guice performs code generation and class loading. We use this stuff for faster reflection, method interceptors, and to proxy circular dependencies.

When loading classes, we need to be careful of:

For each generated class, there's multiple class loaders involved:

The Bridge ClassLoader

Guice uses its bridge class loader unless:

Only classes loaded by the bridge class loader will work in an OSGi environment. Disabling Guice's Bridge ClassLoader

Setting the system property guice.custom.loader to false will cause Guice to use the target class's classloader for all generated classes. Guice's bridge classloader will not be used. Generated Classes and Memory Leaks

Classes can only be garbage collected when all of their instances and the originating classloader are no longer referenced. The bridge class loader is intended to allow generated classes to be garbage collected as quickly as possible.

To minimize the amount of PermGen memory used by Guice-generated classes, avoid intercepting package-private methods.

last edited 2009-12-13 23:46:58 by ysugimura