c# - Array with literal strings -


i having string array initialized literal strings below:

public static void main() {      string[] values = new string[] { "cat", "dog", "mouse", "rat" }; } 

so have following structure on stack , heap:

onstack: variable values holding reference array of string on heap.

onheap: array of string referenced values on stack


but content of each element of array on heap ?

  1. actual string literals ?
  2. references pointing string literals in intern pool ?

edit: question pointed duplicate this question. case different in terms that

  1. another question in context how value type elements of array behave, showed question poser not clear how ref/val type objects allocated on stack/heap.
  2. in question clear how ref/val type elements allocated on stack or heap discussing special case when objects string literals. because has deal intern pool , gc.

in particular case, considering microsoft .net clr (this important position of values, if in stack or heap), you'll have 5 references 5 objects.

to precise, have array of strings (1 object), array of references string (another 4 objects).

the 5 references are:

  • values (in case on stack)
  • 4x references 4x interned strings (contained on heap, in string[] array)

the 5 objects are:

  • an array of string[], contained in heap
  • 4x string objects interned, still fledged objects, difference gc won't ever free them (unless appdomain unloaded)

so

references pointing string literals in intern pool ?


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -