- Home /
Pointer or Copied Value?
Hello
if I have the following code:
public class myClassA
{
....
}
public class myClassB
{
public myClassA[] _myClassA;
public void Awake()
{
MyFunction(_myClassA[]);
}
public void (myClassA classA[])
{
...//I need help here with classA
}
}
So when I know modify classA[] will it also change the values of _myClassA[] or will it create an exact copy of the class?
And how do I generally know which variables get copied and which not? Like I know that int will be copied but GameObject is always a reference.
Best regards,
Fred
Answer by tanoshimi · May 25, 2016 at 10:05 PM
The difference between value types and reference types is explained in https://unity3d.com/learn/tutorials/topics/scripting/data-types
Thank you. But how would this turn out if I would create a myClassA variable inside a void and reference it to a variable outside that void. Will the variable then be deleted at the the end of the function or does it stay stored until no reference is pointing at it anymore?
it will not be cleaned up by garbage collector while there is at least 1 thing referencing it. Think of c++, boost's shared pointers.
However, looped reference is a problem and garbage collector tries to spot them