<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Dynamic_loading</id>
	<title>Dynamic loading - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Dynamic_loading"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Dynamic_loading&amp;action=history"/>
	<updated>2026-05-04T19:19:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Dynamic_loading&amp;diff=4384205&amp;oldid=prev</id>
		<title>imported&gt;Guy Harris: /* In Java */ Fix link. (The class for the Java class loader is called ClassLoader, not &quot;class loader&quot; - I don&#039;t think Java allows spaces in names.)</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Dynamic_loading&amp;diff=4384205&amp;oldid=prev"/>
		<updated>2024-12-22T20:48:02Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;In Java: &lt;/span&gt; Fix link. (The class for the Java class loader is called ClassLoader, not &amp;quot;class loader&amp;quot; - I don&amp;#039;t think Java allows spaces in names.)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Mechanism by which a computer program can load a library (or other binary) into memory}}&lt;br /&gt;
{{distinguish|text=[[active load|dynamic load]]}}&lt;br /&gt;
{{Redirect-distinguish2|Dynamically loaded library|[[dynamic-link library|dynamically linked library]]}}&lt;br /&gt;
{{Use dmy dates|date=July 2019|cs1-dates=y}}&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Dynamic loading&amp;#039;&amp;#039;&amp;#039; is a mechanism by which a [[computer program]] can, at [[Run time (program lifecycle phase)|run time]], load a [[Library (computing)|library]] (or other [[Executable file|binary]]) into memory, retrieve the addresses of functions and variables contained in the library, execute those [[library function|functions]] or access those variables, and unload the library from memory. It is one of the three mechanisms by which a computer program can use some other software within the program; the others are [[static linking]] and [[dynamic linking]]. Unlike static linking and dynamic linking, dynamic loading allows a [[computer program]] to start up in the absence of these libraries, to discover available libraries, and to potentially gain additional functionality.&amp;lt;ref name=&amp;quot;autobook&amp;quot;/&amp;gt;&amp;lt;ref name=&amp;quot;Elf_Dynamic_Loading&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
Dynamic loading was a common technique for IBM&amp;#039;s [[operating systems]] for [[System/360]] such as [[OS/360]], particularly for [[I/O]] [[subroutine]]s, and for [[COBOL]] and [[PL/I]] [[runtime library|runtime libraries]], and continues to be used in IBM&amp;#039;s operating systems for [[z/Architecture]], such as [[z/OS]]. As far as the application programmer is concerned, the loading is largely transparent, since it is mostly handled by the operating system (or its I/O subsystem). The main advantages are:&lt;br /&gt;
&lt;br /&gt;
* Fixes ([[Patch (computing)|patches]]) to the subsystems fixed all programs at once, without the need to relink them&lt;br /&gt;
* Libraries could be protected from unauthorized modification&lt;br /&gt;
&lt;br /&gt;
[[IBM]]&amp;#039;s strategic [[transaction processing]] system, [[CICS]] (1970s onwards) uses dynamic loading extensively both for its [[kernel (operating system)|kernel]] and for normal [[application program]] loading. Corrections to application programs could be made offline and new copies of changed programs loaded dynamically without needing to restart CICS&amp;lt;ref name=&amp;quot;CICS&amp;quot;/&amp;gt;&amp;lt;ref name=&amp;quot;CEMT&amp;quot;/&amp;gt; (which can, and frequently does, run [[24/7]]).&lt;br /&gt;
&lt;br /&gt;
[[Shared libraries]] were added to Unix in the 1980s, but initially without the ability to let a program load additional libraries after startup.&amp;lt;ref name=&amp;quot;spe&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Uses==&lt;br /&gt;
Dynamic loading is most frequently used in implementing [[Plug-in (computing)|software plugins]].&amp;lt;ref name=&amp;quot;autobook&amp;quot;/&amp;gt; For example, the [[Apache Web Server|Apache Web Server&amp;#039;s]] &amp;lt;code&amp;gt;*.dso&amp;lt;/code&amp;gt; &amp;quot;dynamic shared object&amp;quot; plugin files are [[Library (computing)|libraries]] which are loaded at runtime with dynamic loading.&amp;lt;ref name=&amp;quot;apache&amp;quot;/&amp;gt; Dynamic loading is also used in implementing [[computer programs]] where multiple different libraries may supply the requisite functionality and where the user has the option to select which library or libraries to provide.&lt;br /&gt;
&lt;br /&gt;
==In C/C++==&lt;br /&gt;
Not all systems support dynamic loading. [[Unix-like]] operating systems such as [[macOS]], [[Linux]], and [[Solaris (operating system)|Solaris]] provide dynamic loading with the [[C (programming language)|C programming language]] &amp;quot;dl&amp;quot; library. The [[Microsoft Windows|Windows]] [[operating system]] provides dynamic loading through the [[Windows API]].&lt;br /&gt;
&lt;br /&gt;
===Summary===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! [[Unix|Standard POSIX/Unix API]]&lt;br /&gt;
! [[Windows API|Microsoft Windows API]]&lt;br /&gt;
|-&lt;br /&gt;
| Header file inclusion&lt;br /&gt;
| &amp;lt;code&amp;gt;#include &amp;amp;lt;dlfcn.h&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;#include &amp;amp;lt;windows.h&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Definitions for header&lt;br /&gt;
| &amp;lt;code&amp;gt;dl&amp;lt;/code&amp;gt;&lt;br /&gt;
(&amp;lt;code&amp;gt;libdl.so&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;libdl.dylib&amp;lt;/code&amp;gt;, etc. depending on the [[operating system|OS]])&lt;br /&gt;
| &amp;lt;code&amp;gt;kernel32.dll&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Loading the library&lt;br /&gt;
| &amp;lt;code&amp;gt;dlopen&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;LoadLibrary&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;LoadLibraryEx&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Extracting contents&lt;br /&gt;
| &amp;lt;code&amp;gt;dlsym&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;GetProcAddress&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Unloading the library&lt;br /&gt;
| &amp;lt;code&amp;gt;dlclose&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;FreeLibrary&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Loading the library===&lt;br /&gt;
Loading the library is accomplished with &amp;lt;code&amp;gt;LoadLibrary&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;LoadLibraryEx&amp;lt;/code&amp;gt; on [[Microsoft Windows|Windows]] and with &amp;lt;code&amp;gt;dlopen&amp;lt;/code&amp;gt; on [[Unix-like]] [[operating system]]s. Examples follow:&lt;br /&gt;
&lt;br /&gt;
====Most Unix-like operating systems (Solaris, Linux, *BSD, etc.)====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void* sdl_library = dlopen(&amp;quot;libSDL.so&amp;quot;, RTLD_LAZY);&lt;br /&gt;
if (sdl_library == NULL) {&lt;br /&gt;
   // report error ...&lt;br /&gt;
} else {&lt;br /&gt;
   // use the result in a call to dlsym&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====macOS====&lt;br /&gt;
As a [[Unix]] library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void* sdl_library = dlopen(&amp;quot;libSDL.dylib&amp;quot;, RTLD_LAZY);&lt;br /&gt;
if (sdl_library == NULL) {&lt;br /&gt;
   // report error ...&lt;br /&gt;
} else {&lt;br /&gt;
   // use the result in a call to dlsym&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As a [[Application framework|macOS Framework]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void* sdl_library = dlopen(&amp;quot;/Library/Frameworks/SDL.framework/SDL&amp;quot;, RTLD_LAZY);&lt;br /&gt;
if (sdl_library == NULL) {&lt;br /&gt;
   // report error ...&lt;br /&gt;
} else {&lt;br /&gt;
   // use the result in a call to dlsym&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or if the framework or bundle contains Objective-C code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;objc&amp;quot;&amp;gt;&lt;br /&gt;
NSBundle *bundle = [NSBundle bundleWithPath:@&amp;quot;/Library/Plugins/Plugin.bundle&amp;quot;];&lt;br /&gt;
NSError *err = nil;&lt;br /&gt;
if ([bundle loadAndReturnError:&amp;amp;err])&lt;br /&gt;
{&lt;br /&gt;
    // Use the classes and functions in the bundle.&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    // Handle error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Windows====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
HMODULE sdl_library = LoadLibrary(TEXT(&amp;quot;SDL.dll&amp;quot;));&lt;br /&gt;
if (sdl_library == NULL) {&lt;br /&gt;
   // report error ...&lt;br /&gt;
} else {&lt;br /&gt;
   // use the result in a call to GetProcAddress&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Extracting library contents===&lt;br /&gt;
Extracting the contents of a dynamically loaded library is achieved with &amp;lt;code&amp;gt;GetProcAddress&amp;lt;/code&amp;gt; on [[Microsoft Windows|Windows]] and with &amp;lt;code&amp;gt;dlsym&amp;lt;/code&amp;gt; on [[Unix]]-like [[operating system]]s.&lt;br /&gt;
&lt;br /&gt;
====Unix-like operating systems (Solaris, Linux, *BSD, macOS, etc.)====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void* initializer = dlsym(sdl_library, &amp;quot;SDL_Init&amp;quot;);&lt;br /&gt;
if (initializer == NULL) {&lt;br /&gt;
   // report error ...&lt;br /&gt;
} else {&lt;br /&gt;
   // cast initializer to its proper type and use&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
On macOS, when using Objective-C bundles, one can also:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;objc&amp;quot;&amp;gt;&lt;br /&gt;
Class rootClass = [bundle principalClass]; // Alternatively, NSClassFromString() can be used to obtain a class by name.&lt;br /&gt;
if (rootClass)&lt;br /&gt;
{&lt;br /&gt;
    id object = [[rootClass alloc] init]; // Use the object.&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    // Report error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Windows====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
FARPROC initializer = GetProcAddress(sdl_library,&amp;quot;SDL_Init&amp;quot;);&lt;br /&gt;
if (initializer == NULL) {&lt;br /&gt;
   // report error ...&lt;br /&gt;
} else {&lt;br /&gt;
   // cast initializer to its proper type and use&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Converting a library function pointer===&lt;br /&gt;
The result of &amp;lt;code&amp;gt;dlsym()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;GetProcAddress()&amp;lt;/code&amp;gt; has to be converted to a pointer of the appropriate type before it can be used.&lt;br /&gt;
&lt;br /&gt;
====Windows====&lt;br /&gt;
In Windows, the conversion is straightforward, since FARPROC is essentially already a [[function pointer]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
typedef INT_PTR (*FARPROC)(void);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This can be problematic when the address of an object is to be retrieved rather than a function. However, usually one wants to extract functions anyway, so this is normally not a problem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
typedef void (*sdl_init_function_type)(void);&lt;br /&gt;
sdl_init_function_type init_func = (sdl_init_function_type) initializer;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Unix (POSIX)====&lt;br /&gt;
According to the POSIX specification, the result of &amp;lt;code&amp;gt;dlsym()&amp;lt;/code&amp;gt; is a &amp;lt;code&amp;gt;void&amp;lt;/code&amp;gt; pointer. However, a function pointer is not required to even have the same size as a data object pointer, and therefore a valid conversion between type &amp;lt;code&amp;gt;void*&amp;lt;/code&amp;gt; and a pointer to a function may not be easy to implement on all platforms.&lt;br /&gt;
&lt;br /&gt;
On most systems in use today, function and object pointers are &amp;#039;&amp;#039;de facto&amp;#039;&amp;#039; convertible. The following code snippet demonstrates one workaround which allows to perform the conversion anyway on many systems:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
typedef void (*sdl_init_function_type)(void);&lt;br /&gt;
sdl_init_function_type init_func = (sdl_init_function_type)initializer;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above snippet will give a warning on some compilers: &amp;lt;code&amp;gt;warning: dereferencing type-punned pointer will break strict-aliasing rules&amp;lt;/code&amp;gt;. Another workaround is:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
typedef void (*sdl_init_function_type)(void);&lt;br /&gt;
union { sdl_init_function_type func; void * obj; } alias;&lt;br /&gt;
alias.obj = initializer;&lt;br /&gt;
sdl_init_function_type init_func = alias.func;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which disables the warning even if strict aliasing is in effect. This makes use of the fact that reading from a different union member than the one most recently written to (called &amp;quot;[[type punning]]&amp;quot;) is common, and explicitly allowed even if strict aliasing is in force, provided the memory is accessed through the union type directly.&amp;lt;ref name=&amp;quot;gcc-strict-aliasing&amp;quot;/&amp;gt; However, this is not strictly the case here, since the function pointer is copied to be used outside the union. Note that this trick may not work on platforms where the size of data pointers and the size of function pointers is not the same.&lt;br /&gt;
&lt;br /&gt;
====Solving the function pointer problem on POSIX systems====&lt;br /&gt;
The fact remains that any conversion between function and data object pointers has to be regarded as an (inherently non-portable) implementation extension, and that no &amp;quot;correct&amp;quot; way for a direct conversion exists, since in this regard the POSIX and ISO standards contradict each other.&lt;br /&gt;
&lt;br /&gt;
Because of this problem, the POSIX documentation on &amp;lt;code&amp;gt;dlsym()&amp;lt;/code&amp;gt; for the outdated issue 6 stated that &amp;quot;a future version may either add a new function to return function pointers, or the current interface may be deprecated in favor of two new functions: one that returns data pointers and the other that returns function pointers&amp;quot;.&amp;lt;ref name=&amp;quot;POSIX_dlopen&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the subsequent version of the standard (issue 7, 2008), the problem has been discussed and the conclusion was that function pointers have to be convertible to &amp;lt;code&amp;gt;void*&amp;lt;/code&amp;gt; for POSIX compliance.&amp;lt;ref name=&amp;quot;POSIX_dlopen&amp;quot;/&amp;gt; This requires compiler makers to implement a working cast for this case.&lt;br /&gt;
&lt;br /&gt;
If the contents of the library can be changed (i.e. in the case of a custom library), in addition to the function itself a pointer to it can be exported. Since a pointer to a function pointer is itself an object pointer, this pointer can always be legally retrieved by call to &amp;lt;code&amp;gt;dlsym()&amp;lt;/code&amp;gt; and subsequent conversion. However, this approach requires maintaining separate pointers to all functions that are to be used externally, and the benefits are usually small.&lt;br /&gt;
&lt;br /&gt;
===Unloading the library===&lt;br /&gt;
Loading a library causes memory to be allocated; the library must be deallocated in order to avoid a [[memory leak]]. Additionally, failure to unload a library can prevent [[filesystem]] operations on the [[computer file|file]] which contains the library. Unloading the library is accomplished with &amp;lt;code&amp;gt;FreeLibrary&amp;lt;/code&amp;gt; on [[Microsoft Windows|Windows]] and with &amp;lt;code&amp;gt;dlclose&amp;lt;/code&amp;gt; on Unix-like [[operating system]]s. However, unloading a DLL can lead to program crashes if objects in the main application refer to memory allocated within the DLL. For example, if a DLL introduces a new class and the DLL is closed, further operations on instances of that class from the main application will likely cause a memory access violation. Likewise, if the DLL introduces a factory function for instantiating dynamically loaded classes, calling or dereferencing that function after the DLL is closed leads to undefined behaviour.&lt;br /&gt;
&lt;br /&gt;
====Unix-like operating systems (Solaris, Linux, *BSD, macOS, etc.)====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
dlclose(sdl_library);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Windows====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
FreeLibrary(sdl_library);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Special library===&lt;br /&gt;
The implementations of dynamic loading on [[Unix-like]] operating systems and [[Microsoft Windows|Windows]] allow programmers to extract symbols from the currently executing process.&lt;br /&gt;
&lt;br /&gt;
Unix-like operating systems allow programmers to access the global symbol table, which includes both the main executable and subsequently loaded dynamic libraries.&lt;br /&gt;
&lt;br /&gt;
[[Microsoft Windows|Windows]] allows programmers to access symbols exported by the main executable. Windows does not use a global symbol table and has no API to search across multiple modules to find a symbol by name.&lt;br /&gt;
&lt;br /&gt;
====Unix-like operating systems (Solaris, Linux, *BSD, macOS, etc.)====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void* this_process = dlopen(NULL,0);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Windows====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
HMODULE this_process = GetModuleHandle(NULL);&lt;br /&gt;
&lt;br /&gt;
HMODULE this_process_again;&lt;br /&gt;
GetModuleHandleEx(0,0,&amp;amp;this_process_again);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==In Java==&lt;br /&gt;
{{further|Java class loader}}&lt;br /&gt;
In the [[Java programming language]], [[Java class|classes]] can be dynamically loaded using the &amp;#039;&amp;#039;&amp;#039;{{Javadoc:SE|java/lang|ClassLoader}}&amp;#039;&amp;#039;&amp;#039; object. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
Class type = ClassLoader.getSystemClassLoader().loadClass(name);&lt;br /&gt;
Object obj = type.newInstance();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Reflection mechanism also provides a means to load a class if it isn&amp;#039;t already loaded. It uses the classloader of the current class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
Class type = Class.forName(name);&lt;br /&gt;
Object obj = type.newInstance();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, there is no simple way to unload a class in a controlled way. Loaded classes can only be unloaded in a controlled way, i.e. when the programmer wants this to happen, if the classloader used to load the class is not the system class loader, and is itself unloaded. When doing so, various details need to be observed to ensure the class is really unloaded. This makes unloading of classes tedious.&lt;br /&gt;
&lt;br /&gt;
Implicit unloading of classes, i.e. in an uncontrolled way by the garbage collector, has changed a few times in Java. Until Java 1.2. the garbage collector could unload a class whenever it felt it needed the space, independent of which class loader was used to load the class. Starting with Java 1.2 classes loaded via the system classloader were never unloaded and classes loaded via other classloaders only when this other classloader was unloaded. Starting with Java 6 classes can contain an internal marker indicating to the garbage collector they can be unloaded if the garbage collector desires to do so, independent of the classloader used to load the class. The garbage collector is free to ignore this hint.&lt;br /&gt;
&lt;br /&gt;
Similarly, libraries implementing native methods are dynamically loaded using the &amp;lt;code&amp;gt;System.loadLibrary&amp;lt;/code&amp;gt; method. There is no &amp;lt;code&amp;gt;System.unloadLibrary&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
==Platforms without dynamic loading==&lt;br /&gt;
Despite its promulgation in the 1980s through Unix and Windows, some systems still chose not to add—or even to remove—dynamic loading. For example, [[Plan 9 from Bell Labs]] and its successor 9front intentionally avoid dynamic linking, as they consider it to be &amp;quot;harmful&amp;quot;.&amp;lt;ref name=&amp;quot;Cat-V&amp;quot;/&amp;gt; The [[Go (programming language)|Go programming language]], by some of the same developers as Plan 9, also did not support dynamic linking, but plugin loading is available since [https://tip.golang.org/doc/go1.8 Go 1.8] (February 2017). The Go runtime and any library functions are statically linked into the compiled binary.&amp;lt;ref name=&amp;quot;Golang&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
{{Portal|Computer programming}}&lt;br /&gt;
&lt;br /&gt;
{{Div col|colwidth=20em}}&lt;br /&gt;
* [[Compile and go system]]&lt;br /&gt;
* [[DLL Hell]]&lt;br /&gt;
* [[Direct binding]]&lt;br /&gt;
* [[Dynamic binding (computing)]]&lt;br /&gt;
* [[Dynamic dispatch]]&lt;br /&gt;
* [[Dynamic library]]&lt;br /&gt;
* [[Dynamic linker]]&lt;br /&gt;
* [[Dynamic-link library]]&lt;br /&gt;
* [[FlexOS]]&amp;lt;!-- might at a later stage be incorporated in the article body as example of a system supporting dynamic loading/unloading of modular subdrivers --&amp;gt;&lt;br /&gt;
* [[GNU linker]]&lt;br /&gt;
* [[gold (linker)]]&lt;br /&gt;
* [[Lazy loading]]&lt;br /&gt;
* [[Library (computing)]]&lt;br /&gt;
* [[Linker (computing)]]&lt;br /&gt;
* [[Loader (computing)]]&lt;br /&gt;
* [[Name decoration]]&lt;br /&gt;
* [[Prebinding]]&lt;br /&gt;
* [[Prelinking]]&lt;br /&gt;
* [[Relocation (computer science)]]&lt;br /&gt;
* [[Relocation table]]&lt;br /&gt;
* [[Resident System Extension]] (RSX)&amp;lt;!-- dynamic (but not delayed) loading/unloading of modules under CP/M-related systems --&amp;gt;&lt;br /&gt;
* [[Static library]]&lt;br /&gt;
* [[Terminate-and-stay-resident program]] (TSR)&amp;lt;!-- dynamic (but not delayed) loading of system extensions under DOS-related systenms --&amp;gt;&lt;br /&gt;
{{div col end}}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|refs=&lt;br /&gt;
&amp;lt;ref name=&amp;quot;autobook&amp;quot;&amp;gt;[http://sourceware.org/autobook/autobook/autobook_158.html Autoconf, Automake, and Libtool: Dynamic Loading]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Elf_Dynamic_Loading&amp;quot;&amp;gt;{{Cite web |url=http://linux4u.jinr.ru/usoft/WWW/www_debian.org/Documentation/elf/node7.html |title=Linux4U: ELF Dynamic Loading |access-date=31 December 2007 |archive-url=https://web.archive.org/web/20110311170401/http://linux4u.jinr.ru/usoft/WWW/www_debian.org/Documentation/elf/node7.html |archive-date=11 March 2011 |url-status=dead }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;CICS&amp;quot;&amp;gt;{{Cite web |url=http://publib.boulder.ibm.com/infocenter/cicsts/v3r1/index.jsp?topic=/com.ibm.cics.ts31.doc/dfhp3/dfhp3oq.htm |title=Using the CICS-supplied procedures to install application programs}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;CEMT&amp;quot;&amp;gt;{{Cite web |url=http://www-01.ibm.com/support/docview.wss?uid=swg21031546 |title=IBM CEMT NEWCOPY or PHASEIN request fails with NOT FOR HOLD PROG - United States |date=2013-03-15}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;spe&amp;quot;&amp;gt;{{cite journal |title=An approach to genuine dynamic linking |author-first1=W. Wilson |author-last1=Ho |author-first2=Ronald A. |author-last2=Olsson |date=1991 |journal=Software: Practice and Experience |volume=21 |issue=4 |pages=375–390 |doi=10.1002/spe.4380210404 |citeseerx=10.1.1.37.933|s2cid=9422227 }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;apache&amp;quot;&amp;gt;{{Cite web |url=http://httpd.apache.org/docs/1.3/dso.html |title=Apache 1.3 Dynamic Shared Object (DSO) Support |access-date=2007-12-31  |archive-date=2011-04-22  |archive-url=https://web.archive.org/web/20110422182003/http://httpd.apache.org/docs/1.3/dso.html |url-status=dead }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;gcc-strict-aliasing&amp;quot;&amp;gt;[https://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Optimize-Options.html#index-fstrict_002daliasing-721 GCC 4.3.2 Optimize Options: -fstrict-aliasing]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;POSIX_dlopen&amp;quot;&amp;gt;[http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html POSIX documentation on &amp;lt;code&amp;gt;dlopen()&amp;lt;/code&amp;gt;] (issues 6 and 7).&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Cat-V&amp;quot;&amp;gt;{{cite web |title=Dynamic Linking |url=http://harmful.cat-v.org/software/dynamic-linking/ |website=cat-v.org |publisher=9front |access-date=2014-12-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Golang&amp;quot;&amp;gt;{{cite web |url=http://golang.org/doc/faq#Why_is_my_trivial_program_such_a_large_binary |title=Go FAQ}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Further reading==&lt;br /&gt;
* {{cite book |author-first1=Abraham |author-last1=Silberschatz |author-first2=Peter Baer |author-last2=Galvin |author-first3=Greg |author-last3=Gagne |title=Operating System Concepts |chapter=Chapter 8.1.4 &amp;quot;Dynamic Loading&amp;quot; and Chapter 8.1.5 &amp;quot;Dynamic Linking and shared libraries&amp;quot; |date=2005 |publisher=[[J. Wiley &amp;amp; Sons]] |isbn=978-0-471-69466-3}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
* General Links&lt;br /&gt;
** [https://web.archive.org/web/20110311170401/http://linux4u.jinr.ru/usoft/WWW/www_debian.org/Documentation/elf/node7.html Dynamic Loading] on [[Linux4U]]&lt;br /&gt;
** [http://httpd.apache.org/docs/current/dso.html Dynamic Shared Object (DSO) Support] by [[Apache HTTP Server|Apache]]&lt;br /&gt;
** [https://web.archive.org/web/20080609064104/http://www.informit.com/guides/content.aspx?g=cplusplus&amp;amp;seqNum=153 C++ Dynamic Linking By Example]&lt;br /&gt;
** [https://github.com/danfuzz/dl-example Dynamic Library Loading Example] (complete but concise working example)&lt;br /&gt;
** [https://developer.apple.com/library/mac/#DOCUMENTATION/DeveloperTools/Conceptual/DynamicLibraries/000-Introduction/Introduction.html#//apple_ref/doc/uid/TP40001908-SW1 Dynamic Library Programming Topics from Apple Developer Connection (targeted to macOS)]&lt;br /&gt;
* C/C++ Unix API:&lt;br /&gt;
** [http://www.opengroup.org/onlinepubs/009695399/functions/dlopen.html dlopen]&lt;br /&gt;
** [http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html dlsym]&lt;br /&gt;
** [http://www.opengroup.org/onlinepubs/009695399/functions/dlclose.html dlclose]&lt;br /&gt;
* C/C++ Windows API:&lt;br /&gt;
** [http://msdn2.microsoft.com/en-us/library/ms684175.aspx LoadLibrary]&lt;br /&gt;
** [http://msdn2.microsoft.com/en-us/library/ms683212(VS.85).aspx GetProcAddress]&lt;br /&gt;
** [http://msdn2.microsoft.com/en-us/library/ms683152(VS.85).aspx FreeLibrary]&lt;br /&gt;
** [http://msdn.microsoft.com/en-us/library/151kt790.aspx Delay-Loaded DLLs]&lt;br /&gt;
* Java API:&lt;br /&gt;
** [http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ClassLoader.html ClassLoader]&lt;br /&gt;
** [http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html Class]&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Dynamic Loading}}&lt;br /&gt;
[[Category:Computer libraries]]&lt;br /&gt;
[[Category:Operating system technology]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Guy Harris</name></author>
	</entry>
</feed>