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 "" 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 Heap View

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)
                   .Where(t => t.Name.EndsWith("Validator"))




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

  • 3
    I don't think it's glass mapper. thousands of people use it around the world. I do assume it's some of your code which is holding references to glass mapper objects and that's why they are not picked up by garbage collector
    – Marek Musielak
    Sep 8, 2019 at 9:17
  • I have seen this in the past when you DI up a glass instance and dispose of it improperly. Or you are are newing up some glass references in a static method. Either way, its not glass. Its your code.
    – Chris Auer
    Sep 8, 2019 at 12:08
  • Sitecore Support provided this link hence thought of asking: kb.sitecore.net/articles/874459 Glasss DI comes out of the box and we scanned through out the project and didn't find any static method holding reference to glass
    – Nil Pun
    Sep 9, 2019 at 7:07
  • Updated finding from sitecore support..
    – Nil Pun
    Sep 9, 2019 at 8:04
  • Perhaps add some code around this scenario? Sep 9, 2019 at 20:59

1 Answer 1


We have experienced something like that once on production environment, after some period of time servers were running out of memory. With help with Sitecore support, they pointed out we have a lot of GlassMapper objects, coming from casting items into GlassMapper objects.

We have created custom extension method:

public static T GlassCast<T>(this Item item, bool isLazy = false, bool inferType = false) where T : class
    var service = (SitecoreService) ContainerManager.Container.Resolve<ISitecoreService>(item.Database.Name);
    return service.Cast<T>(item, isLazy, inferType);

We have ISitecoreService registered as Singleton in Windsor container.

    .DependsOn(Dependency.OnValue("databaseName", "web")).Named("web"));
  • Thank @jjczopek, good point. But we have already handled this one.
    – Nil Pun
    Sep 24, 2019 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.