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 ?
- actual string literals ?
- references pointing string literals in intern pool ?
edit: question pointed duplicate this question. case different in terms that
- 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.
- 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 string
s (1 object), array of references string
(another 4 objects).
the 5 references are:
values
(in case on stack)- 4x references 4x interned
string
s (contained on heap, instring[]
array)
the 5 objects are:
- an array of
string[]
, contained in heap - 4x
string
objects interned, still fledgedobject
s, difference gc won't ever free them (unlessappdomain
unloaded)
so
references pointing string literals in intern pool ?
Comments
Post a Comment