Highlighted

AEM Sling Model Injection vs Constructor Injection Memory Consumption | AEM Community Blog Seeding

kautuk_sahni

Community Manager

27-05-2020

BlogImage.jpg

AEM Sling Model Injection vs Constructor Injection Memory Consumption by Sourcedcode Blog

Abstract

Sling Models field injectors are used to support injection of AEM Library-specific context objects. For example, @ScriptVariable SightlyWCMMode will inject the WCMMode object, @ScriptVariable Resource will inject the current resource object, and @ScriptVariable Style will inject the Style object.

With the Apache Sling Model’s injector specific annotations, we are able to inject AEM Services, Objects, Configuration, etc… directly into the context of the Sling Model easily without much hassle.

What is the catch? Whenever we are injecting objects into our Sling Models via field injection, an instantiated Sling Model adaptable is actually storing a reference of those object in memory; stored injected objects in the Sling Model instance will consume memory.
The Sling Model constructor injection is also supported (as of Sling Models 1.1.0), and its documented that it does not store the reference to the adaptable, lets test this out.

In this article, we will test the Sling Model memory consumption with two scenarios:
1. Test 1: Sling Model Field Injection
2. Test 2: Sling Model Constructor Injection
3. Conclusion

Read Full Blog

AEM Sling Model Injection vs Constructor Injection Memory Consumption

Q&A

Please use this thread to ask the related questions.

AEM AEMEBlogSeeding Experience Manager