Memory Question

  • Thread starter Thread starter BuddyWork
  • Start date Start date
B

BuddyWork

Hello,

If you have the following code

public class Logging
{
public static void LogMessage(string myData)
{
// code logs some data
}
}

public class Car
{
public void Test()
{
Logging.LogMessage("this is a very long string");
}
}

My Question is that when the data from function Test is passed through
to the LogMessage the memory is stored on the stack, when the Test
function and LogMessage is out of scope, does the memory move to the
heap in GEN 0, and then it might work its way to GEN 2.
 
BuddyWork said:
Hello,

If you have the following code

public class Logging
{
public static void LogMessage(string myData)
{
// code logs some data
}
}

public class Car
{
public void Test()
{
Logging.LogMessage("this is a very long string");
}
}

My Question is that when the data from function Test is passed through
to the LogMessage the memory is stored on the stack, when the Test
function and LogMessage is out of scope, does the memory move to the
heap in GEN 0, and then it might work its way to GEN 2.

The data (the string) is not stored on the stack when calling Test, what is
passed is the value of the reference to the string object.

Willy.
 
Back
Top