0

If i create a new object in any Method, so it will be local, will it be contained in heap? or it will be contained on stack, cuz it is local

i try googling, but i have no results

Rand Random
  • 7,300
  • 10
  • 40
  • 88
  • the object is in the heap referenced from the stack, it is the only value type that remains in the stack. – Maytham Fahmi Dec 31 '22 at 14:37
  • "You should consider the question of where objects get allocated as an implementation detail. [...] While reference types are always allocated on the heap in current implementations, value types may be allocated on the stack -- but aren't necessarily. A value type is only allocated on the stack when it is an unboxed non-escaping local or temporary variable that is not contained within a reference type and not allocated in a register." https://stackoverflow.com/a/4487320/1043380 – gunr2171 Dec 31 '22 at 14:37

0 Answers0