# What am I misunderstanding about arrays?

**URL:** <https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488>\
**Category:** General\
**Created:** [January 17, 2026, 3:39am UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488 "2026-01-17T03:39:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![C\_L\_Hinkle](https://forum.xojo.com/user_avatar/forum.xojo.com/c_l_hinkle/32/3319_2.png) [@C\_L\_Hinkle](https://forum.xojo.com/u/C_L_Hinkle)\
**Post date:** [January 17, 2026, 3:39am UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/1 "2026-01-17T03:39:22Z")

</div>

I see a behavior that surprised me — and I honestly didn’t think it’s been working this way unless I’m going crazy. But maybe you can explain this to me. I have an array named Board which is 8x8.

`Var tempBoard(7, 7) As String = board`  
`tempBoard(7,7) = “X”`  
`tempBoard(7,6) = “X”`  
`tempBoard(7,5) = “X”`  
`tempBoard(7,4) = “X”`

This code is setting positions 7,7 through 7,4 in tempBoard to “X,” just like I expected.  
But it’s also setting the values 7,7 through 7,4 in. Board to “X.” So I’m guessing that tempBoard and Board are sharing a memory location.

But why? Why wasn’t tempBoard initialized as an independent variable? I can work around it by running through a loop that copies the values from board to tempBoard. But I’d like to understand why it’s behaving like this.

---

<div class="post-metadata">

**Author:** ![Eric\_Williams](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/ecccb3/32.png) [@Eric\_Williams](https://forum.xojo.com/u/Eric_Williams)\
**Post date:** [January 17, 2026, 3:56am UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/2 "2026-01-17T03:56:23Z")

</div>

In your declaration for the array, you are assigning it the value of `board`. An array is an object, and it obeys all the normal rules about references. The variables `tempBoard` and `board` point to the same array object in your code, so any modifications affect the same object.

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [January 17, 2026, 3:13pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/3 "2026-01-17T15:13:10Z")

</div>

In my opinion (not shared by everyone) Xojo Arrays are “weird” with some complicated behavior - in short, it’s not always obvious when a new array object is or is not created.

You may find this discussion interesting: [Xojo WTF](https://forum.xojo.com/t/xojo-wtf/70510)

---

<div class="post-metadata">

**Author:** ![Michael\_Hußmann](https://forum.xojo.com/user_avatar/forum.xojo.com/michael_hu%C3%9Fmann/32/438_2.png) [@Michael\_Hußmann](https://forum.xojo.com/u/Michael_Hu%C3%9Fmann)\
**Post date:** [January 17, 2026, 4:40pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/4 "2026-01-17T16:40:38Z")

</div>

> [@Mike\_D](#):
>
> it’s not always obvious when a new array object is or is not created.

A new array is created when you declare it, call the Array function, or call ToArray. I may have missed another method creating a new array but these would be the main ways.

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [January 17, 2026, 5:15pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/5 "2026-01-17T17:15:51Z")

</div>

Another way is to use [ParamArray — Xojo documentation](https://documentation.xojo.com/api/language/paramarray.html)

```auto
Public Function Foobar(ParamArray x as Integer) As integer()
  return x // in this function, x is a newly created array containing the parameters
End Function

var xx() as Integer = Foobar(1,2,3)

```

---

<div class="post-metadata">

**Author:** ![C\_L\_Hinkle](https://forum.xojo.com/user_avatar/forum.xojo.com/c_l_hinkle/32/3319_2.png) [@C\_L\_Hinkle](https://forum.xojo.com/u/C_L_Hinkle)\
**Post date:** [January 17, 2026, 9:00pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/6 "2026-01-17T21:00:56Z")

</div>

And here’s a follow-up question now.

I’ve also assumed that if I pass an array as a parameter to a subroutine, I’m passing it by value and not by memory location. And if I change a member of the array in the routine, the change is not carried back to the calling routine.

---

<div class="post-metadata">

**Author:** ![brian\_franco](https://forum.xojo.com/user_avatar/forum.xojo.com/brian_franco/32/156_2.png) [@brian\_franco](https://forum.xojo.com/u/brian_franco)\
**Post date:** [January 17, 2026, 9:11pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/7 "2026-01-17T21:11:52Z")

</div>

[Passing an Array to a Method: By Ref or Not](https://forum.xojo.com/t/passing-an-array-to-a-method-by-ref-or-not/86551/43)

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [January 17, 2026, 10:11pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/8 "2026-01-17T22:11:19Z")

</div>

> [@C\_L\_Hinkle](#):
>
> I’ve also assumed that if I pass an array as a parameter to a subroutine, I’m passing it by value and not by memory location. And if I change a member of the array in the routine, the change is not carried back to the calling routine.

And your assumption would be incorrect. You are passing a reference to the array, not a copy of it.

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [January 17, 2026, 10:12pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/9 "2026-01-17T22:12:48Z")

</div>

in Xojo, the Array object itself is always passed _by reference_, so a function gets a pointer to the actual array, and any changes made in the function are visible on the original array outside the function.

You can also pass the Array parameter [ByRef](https://documentation.xojo.com/api/language/byref.html) but this means something different: inside a function with a ByRef Array parameter, the function can change the actual reference itself.

Imagine this:

```auto

Public Sub foo(x() as integer)
  x(0) = 99
  x = nil // this has no effect outside the function
End Sub
var a() as integer = Array(1,2,3)

Call foobar(a) // now a() contains (99,1,3)

```

vs. using ByRef

```auto
Public Sub bar(ByRef x() as integer)
  x = Array(7,8,9)
End Sub

var a() as integer = Array(1,2,3)
var b() as integer = a // b is a reference, pointing to a()

Call bar(b)

// at this point, 
// a and b now point to different array objects
// a = (7,8,9)
// b = (1,2,3) 

```

Subtle, but important difference.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [January 17, 2026, 10:14pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/10 "2026-01-17T22:14:37Z")

</div>

> [@Mike\_D](#):
>
> In my opinion (not shared by everyone) Xojo Arrays are “weird”

That’s fair. But remember that we’re dealing with a home-grown compiler. It’s bound to have some quirks.

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [January 17, 2026, 10:21pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/11 "2026-01-17T22:21:34Z")

</div>

I think the documentation could be better, for example this section ([link](https://documentation.xojo.com/getting_started/using_the_xojo_language/collections_of_data.html#array-assignment)):

> ```auto
> var names(2), copyNames(2) As String
> names = Array("Fred", "Ginger", "Stanley")
> copyNames = names
> 
> ```
> 
> The last statement assigns the values of all three elements of names to the first three elements of copyNames. If copyNames had fewer elements than names, then additional elements would first be added to copyNames and the assignment of all the elements of names to copyNames would be completed.

To me this is unclear, and can be read to imply that the array values are copied, but that’s not what happens.

---

<div class="post-metadata">

**Author:** ![C\_L\_Hinkle](https://forum.xojo.com/user_avatar/forum.xojo.com/c_l_hinkle/32/3319_2.png) [@C\_L\_Hinkle](https://forum.xojo.com/u/C_L_Hinkle)\
**Post date:** [January 17, 2026, 10:22pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/12 "2026-01-17T22:22:35Z")

</div>

Between reading these replies and reading the thread that was linked to, I have no idea at all what to expect when I pass an array to a routine. It’s probably the terminology that gets me confused. I’ll just go test it for myself.

---

<div class="post-metadata">

**Author:** ![brian\_franco](https://forum.xojo.com/user_avatar/forum.xojo.com/brian_franco/32/156_2.png) [@brian\_franco](https://forum.xojo.com/u/brian_franco)\
**Post date:** [January 17, 2026, 10:27pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/13 "2026-01-17T22:27:33Z")

</div>

why is it unclear?

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [January 17, 2026, 10:33pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/14 "2026-01-17T22:33:26Z")

</div>

Arrays are great for prototyping, but usually you will write better code by defining a custom Class:

- a Class can have a proper Constructor()
- a Class controls access: private data and methods can be hidden from the public
- a Class can have Shared properties which are shared among all instances of a class
- a Class can implement handy methods such as Operator\_Convert() which can convert to/from other data types.
- a Class can implement a .Clone() or .Copy() method which makes a new copy of itself.

See [Class properties, methods and events — Xojo documentation](https://documentation.xojo.com/getting_started/object-oriented_programming/class_properties-_methods_and_events.html)

---

<div class="post-metadata">

**Author:** ![Eric\_Williams](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/ecccb3/32.png) [@Eric\_Williams](https://forum.xojo.com/u/Eric_Williams)\
**Post date:** [January 17, 2026, 10:34pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/15 "2026-01-17T22:34:04Z")

</div>

Xojo uses the LLVM compiler these days. It translates your Xojo down to an intermediate representation that is then compiled to bytecode by LLVM. (Note that the Android platform uses a completely different system)

This decision is one of the best they ever made - sitting on top of LLVM has allowed us to inherit all the benefits of ongoing LLVM development without Xojo having to roll it themselves. It is why we have XojoScript, for starters. 😁

---

<div class="post-metadata">

**Author:** ![Eric\_Williams](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/ecccb3/32.png) [@Eric\_Williams](https://forum.xojo.com/u/Eric_Williams)\
**Post date:** [January 17, 2026, 10:38pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/16 "2026-01-17T22:38:14Z")

</div>

> [@C\_L\_Hinkle](#):
>
> I’ve also assumed that if I pass an array as a parameter to a subroutine, I’m passing it by value and not by memory location

You are passing it by reference. One important aspect of the Xojo language is that it does not make copies of objects for you. Wherever you pass around an object, you are passing a reference to it. Xojo will not make a copy of an array, for example, whereas it will make a copy of an intrinsic like integer or color.

---

<div class="post-metadata">

**Author:** ![Michael\_Hußmann](https://forum.xojo.com/user_avatar/forum.xojo.com/michael_hu%C3%9Fmann/32/438_2.png) [@Michael\_Hußmann](https://forum.xojo.com/u/Michael_Hu%C3%9Fmann)\
**Post date:** [January 17, 2026, 11:12pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/17 "2026-01-17T23:12:57Z")

</div>

> [@Mike\_D](#):
>
> can be read to imply that the array values are copied, but that’s not what happens.

The documentation claims otherwise: “If copyNames had fewer elements than names, then additional elements would first be added to copyNames and the assignment of all the elements of names to copyNames would be completed.” There is no implication; the documentation explicitly states that all the elements get copied and the receiving array is redimensioned first to make sure they all fit.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [January 17, 2026, 11:58pm UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/18 "2026-01-17T23:58:17Z")

</div>

LLVM did not replace the Xojo compiler, it enhances it. The Xojo compiler produces an intermediate format that is fed to LLVM.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [January 18, 2026, 12:00am UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/19 "2026-01-18T00:00:36Z")

</div>

That is a really unfortunate description in the documentation. It does go on to say that the 2 variables point to the same array in the next paragraph, but the section you quote is very misleading.

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [January 18, 2026, 12:01am UTC](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488/20 "2026-01-18T00:01:22Z")

</div>

> [@Michael\_Hußmann](#):
>
> There is no implication; the documentation explicitly states that all the elements get copied and the receiving array is redimensioned first to make sure they all fit.

Right, but this is simply not true : the array items _are never copied._

What happens is simply the reference for one array is replaced by the other one.

The end result is basically the same as what’s described, but the process described is incorrect.

[Next page](https://forum.xojo.com/t/what-am-i-misunderstanding-about-arrays/87488.md?page=2)
