Skip to content

Files

Latest commit

 

History

History
19 lines (12 loc) · 848 Bytes

ClassForName.md

File metadata and controls

19 lines (12 loc) · 848 Bytes

Pattern: Use of Class.forName()

Issue: -

Description

Using Class.forName(...) is a common way to add dynamic behavior to a system. However, using this method can cause resource leaks because the classes can be pinned in memory for long periods of time. If you're forced to do dynamic class loading then use ClassLoader.loadClass instead. All variations of the Class.forName(...) method suffer from the same problem.

Example of violations:

Class.forName('SomeClassName')
Class.forName(aClassName, true, aClassLoader)

Further Reading