Question about array shallow copy in C# -


Just to make sure that I understand the upheaval copies of reference types and I have a huge memory leak I am not creating:

  // log adds text at the beginning of RTB / / log RTB is trimed for 100 lines var line = new string [rtbLog.Lines. Length + 1]; Line [0] = "text"; Array.Copy (RTBOG.Lines, 0, Line, 1, RTBLog.LangeLange); If (lines lang> 100) {array Resize (Ref: Line, 100); } RtbLog.Lines = Rows;  

This will first copy the referee into lines in RFBLog. Then it will be copied from lines in a new string array of the first 100 referees.

rtblog The array was originally referenced, the array is initially referred to in rows (before context), and in the end no string lines are included (after resizing), all garbage is collected. (I hope that makes sense)

Correct?

array. Recycling method is a bit of a misnomer it should be really named CopyToNewArrayWithSize. Under the hood, this API will create a new array and copy that data into that data. The new array is then returned from context.

By resetting the Lines property to the new array for garbage collection, you successfully removed the original reference of the array. Unless there is any other reference for the array, garbage will be collected at some point in the future.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -