The method is essentially a “piece” of codes of operations (machine operations) located in the code section (read-only) of the executable image.
Thus, methods have nothing to do with the stack (in terms of the memory in which they reside).
However, they access the stack when they perform operations on local variables.
A class instance does not "contain" class methods, but only class attributes (variables that you define in the class), and possibly a pointer to the class V-table (if you define one or more virtual functions in the class or in one of its base classes).
While the method works with non-statistical local variables or non-stationary member variables, it is thread safe, since these variables are allocated on the stack each time the method is called, and each thread has its own stack (its separate area inside the entire stack, to be more precise).
Once a method works with variables that are not allocated on the stack (static local variables, static member variables, static global variables, or non-static global variables), it becomes unsafe and should be treated as such (usually with the appropriate OS resources, such as semaphores, mutexes, etc.).
source share