0

When a bean is created by spring container, only one object (default is singleton) lives in the heap memory, while all injected instances in controllers or services via autowiring are created in stack.

Is the above statement true?

CodeBender
  • 267
  • 4
  • 14

1 Answers1

1

while all injected instances in controllers or services via autowiring are created in stack.

No. Where did you get that idea? All objects are stored in the heap. Local variables are stored on the stack but reference objects in the heap or primitives stored on the stack. This has nothing to do with Spring and everything to do with the Java language and JVM implementations.

Related:

Community
  • 1
  • 1
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724