Junior — Middle
Is the prototype object removed immediately after injection?
sobes.tech AI
Answer from AI
An object with a prototype, injected through a scope with prototype scope (for example, in Spring Framework), is not immediately removed after injection. Such an object is recreated on each request (each call), and its lifecycle is limited to the duration of its use in that specific place.
That is:
- A new instance of the object is created for each injection request.
- After the object is no longer used (for example, the method has finished), it becomes available for garbage collection.
- Garbage collection occurs automatically by the JVM when the object is no longer reachable.