Skip to content

ArchLoader.Build() throws System.OutOfMemoryException #399

Description

@Gargameleto

When calling following code multiple times with different lists of assemblies:

            var archLoader = new ArchLoader();
            archLoader = archLoader.LoadAssembliesIncludingDependencies(assemblies);
            ArchUnitNET.Domain.Architecture architectureUnderTest = archLoader.Build();

somewhen an OutOfMemoryException is thrown.

The reason is that the internal static cache (ArchitectureCache) grows until there is no memory.

The problem can be avoided by following HACK, (which is no real option):

        private static void ClearInternalCache(ArchLoader archLoader)
        {
            System.Reflection.FieldInfo archBuilderField = archLoader.GetType().GetField("_archBuilder", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            object archBuilderValue = archBuilderField.GetValue(archLoader);
            System.Reflection.FieldInfo architectureCacheField = archBuilderValue.GetType().GetField("_architectureCache", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            object architectureCacheValue = architectureCacheField.GetValue(archBuilderValue);
            System.Reflection.MethodInfo clearMethod = architectureCacheValue.GetType().GetMethod("Clear");
            clearMethod.Invoke(architectureCacheValue, null);
        }

Therefore the cache mechanism shall be extended to be configurable or to be turned off so that OutOfMemoryException can be avoided.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions