We have been seeing the high CPU and constant growth of memory. When analyzing the memory dump I noticed that the memory is occupied by 2 million Glass Mapper objects.
Has anyone faced this issue and has possible fixes?
We are using Glass Mapper version "4.3.4.197" and Sitecore 8.2 update 1:
Below is finding from sitecore
Based on provided dump, top memory consumer is glass mapper. Here is a list of most memory consuming types, consuming from 25MB to 300MB in descending order
UPDATE: Looking at memory dump, the Validation Factory Below is holding all the glass objects. And this factory is referenced by Autofac Root.
Any suggestion on how this code below can be fixed?
public class AutofacValidatorFactory : ValidatorFactoryBase
{
private readonly IComponentContext _context;
public AutofacValidatorFactory(IComponentContext context)
{
_context = context;
}
public override IValidator CreateInstance(Type validatorType)
{
object instance;
if (!_context.TryResolve(validatorType, out instance)) return null;
return instance as IValidator;
}
}
public class ValidationModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterAssemblyTypes(ThisAssembly)
.Where(t => t.Name.EndsWith("Validator"))
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
builder.RegisterType<FluentValidationModelValidatorProvider>().As<ModelValidatorProvider>();
builder.RegisterType<AutofacValidatorFactory>().As<IValidatorFactory>();
base.Load(builder);
}
}
UPDATE: Completely got rid of slow AUTOFAC but still seeing memory growth. I've created a separate question for that:
Sitecore 8.2 memory leak - SitecoreRequestScopeModule holding many objects