Skip to content

Have MultiLibraryClassLoader instances keep their ClassLoader alive - #244

Draft
mjcarroll wants to merge 1 commit into
rollingfrom
mjcarroll/multi-loader-ownership
Draft

mjcarroll wants to merge 1 commit into
rollingfrom
mjcarroll/multi-loader-ownership

Conversation

@mjcarroll

@mjcarroll mjcarroll commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Description

MultiLibraryClassLoader kept its ClassLoaders in a process-wide static vector. Loaders whose instances outlived the MultiLibraryClassLoader were never released, so their libraries were never unloaded, and a static MultiLibraryClassLoader read that vector after it was destroyed at exit (part of #33).

Each MultiLibraryClassLoader now owns its loaders as shared_ptrs, and each instance it creates holds a shared_ptr to its loader. This removes the static vector and the ClassLoaderDependency workaround.

Is this user-facing behavior change?

No API change. ABI changes, so rolling only.

Did you use Generative AI?

Claude Code (Claude Opus 5.5) wrote the change; I reviewed it.

Additional Information

Follow-up to #240. New test MultiClassLoaderTest.instanceOutlivesLoader; its non-lazy cases fail on rolling.

MultiLibraryClassLoader kept every ClassLoader it created in a
process-wide static vector so loaders survived while their instances
were alive. Loaders whose instances outlived the MultiLibraryClassLoader
stayed there until process exit, and without on-demand unloading their
libraries were never unloaded.

Own the loaders per MultiLibraryClassLoader instead, and have each
instance hold a shared_ptr to its ClassLoader. A loader now lives
exactly as long as its MultiLibraryClassLoader or its last instance,
and the static vector and its destruction-order workaround go away.

Signed-off-by: Michael Carroll <mjcarroll.oss@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant