Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 206467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:38:55+00:00 2026-05-11T17:38:55+00:00

Just to make sure I’m understanding shallow copies of reference types correctly and that

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:38:55+00:00Added an answer on May 11, 2026 at 5:38 pm

    The Array.Resize method is a bit of a misnomer. It should really be named CopyToNewArrayWithSize. Under the hood, this API will create a new array and copy the specified data into that array. The new array is then returned by reference.

    As for garbage collection. By reseting the Lines property to the new array, you did successfully remove the original reference to the array. As long as there are no other references to the array, it will be garbage collected at some point in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize that I can just make sure I don't have the service open
Guys I know this question is silly but just to make sure: Having in
Just want to make sure one thing. In a windows machine (either a desktop
I'd just like to make sure I understand what PyEphem is doing with angles.
Hi I just want to make sure I have these concepts right. Overloading in
I'm still picking up ObjC and I'm just trying to make sure I understand
I am doing a md5 hash, and just want to make sure the result
I know I could just make all the Mix_Musics public, and not worry about
I have just started to work with jquery so I need to make sure
I need to make sure that PHP sites that I administrate, don't have any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.