Runtime
Since Java runs VM , it is impractical to allocate memory in compile time.
"Local variables", such as function arguments or variables inside a function, are only "allocated" on the stack (primitive value or reference). Objects are always created on the heap .
But: everything related to memory management (allocation, deallocation, garbage collection) depends on the JVM implementation and occurs only at runtime (with the exception of primitive and string constants of course).
source share