asp.net-mvcmemory-leaksstructuremapstructuremap4

What happens if StructureMap Registry has duplicate scan?


I'm trying to dig into a memory leak in my MVC web app and one thing i noticed is that my DefaultRegistry for StructureMap had a duplicated a scan...scan.TheCallingAssembly():

    public DefaultRegistry()
    {
        Scan(
            scan =>
            {                    
                scan.TheCallingAssembly();
                scan.WithDefaultConventions();                    
                scan.TheCallingAssembly();
           });
    }

Would this cause a problem? Could it cause a memory leak? (Please be the problem). I'm publishing the correction tonight, so i'll find out eventually if that fixes the problem or not; but it would be nice to know for certain if duplicate scan methods have any side affects.

Also, is there any significance in the order in which the scan methods appear? Does scan.WithDefaultConventions() need to come last, or first, or does it matter?


Solution

  • Here's the relevant code in StructureMap: https://github.com/structuremap/structuremap/blob/master/src/StructureMap/Graph/AssemblyScanner.cs#L29-L30.

    So no, StructureMap will not double scan the same assembly in any one call to Scan(). You could potentially create duplication if you do the same logical thing in multiple Scan() operations, but at least in the case up above those particular conventional registrations would not add the same type twice.

    And no, it doesn't matter in what order you declare assemblies and registration conventions. The registration conventions would be executed in the order you define them, so you would see that reflected in dependency ordering in a few cases.