Just to make sure I'm understanding shallow copies of reference types correctly and that I'm not constructing a huge memory leak here:
// Adds text to the beginning of the log RTB
// Also keeps the log RTB trimmed to 100 lines
var lines = new string[rtbLog.Lines.Length + 1];
lines[0] = "text";
Array.Copy(rtbLog.Lines, 0, lines, 1, rtbLog.Lines.Length);
if (lines.Length > 100)
{
Array.Resize(ref lines, 100);
}
rtbLog.Lines = lines;
This would firstly copy the refs to the strings in rtbLog.Lines into lines. Then it would copy the first 100 refs from lines into a new string array.
Meaning the array that rtbLog.Lines was originally referencing, the array initially referenced by lines (before the resize), and lastly any strings not contained in lines (after the resize), all get garbage collected. (I hope that makes sense)
Correct?