Skip to content

Commit f081760

Browse files
committed
Update README.asciidoc
1 parent 6b76857 commit f081760

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

projects/README.asciidoc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,22 @@ Consistent programming experience::
308308
Because the Project API provides an abstract model for interacting with existing and creating new projects, it is used in a number of addons and should be considered the standard approach for project manipulation.
309309

310310
ClassLoaderFacet::
311-
This addon introduces a ClassLoaderFacet that provides a URLClassLoader from the project dependencies.
312-
+
311+
This facet exposes a `URLClassLoader` that encompasses all `Dependency` instances on which this project depends. It also includes the compiled/fully built `PackagingFacet#getFinalArtifact()` from the project sources itself.
312+
This is the equivalent of class-loading the entire project classpath.
313313
[source,java]
314314
----
315315
ClassLoaderFacet facet = project.getFacet(ClassLoaderFacet.class);
316316
// This classloader contains all the project classes and their dependencies
317317
try (URLClassLoader classLoader = facet.getClassLoader()) {
318318
// Load classes and use the reflection API to introspect classes
319319
Class<?> clazz = classLoader.loadClass("com.example.Foo");
320-
320+
}
321321
----
322-
322+
323+
[WARNING]
324+
You *MUST* call `URLClassLoader#close()` when finished with this object. Failure to close this object upon completion will result in fatal memory leaks over time. If the scope of work is appropriate, consider using a try-with-resources block to encapsulate the operations and automatically clean up any ClassLoader resources.
325+
326+
[IMPORTANT]
327+
You must also clean up and release any `Class` references that were produced by this `ClassLoader`. It is not enough to close this. Held `Class` references will keep the `ClassLoader` from being garbage collected.
328+
329+

0 commit comments

Comments
 (0)