I can't really make any sense of this. I thought the whole point of a Ref was to point at the object, rather than copy the value, which in my understanding should mean that it tracks changes made to the object later. Does

After writing the above, I guess I'm going to try to answer my own question.

Presumably NWP text objects are immutables, and an array is (something like) a linked list. So every change to a text object really does create a brand new object and the linked list is just updated to have its (in this case 4th) item point to the new object. The Ref object keeps pointing at the original text object.

Generally you do not need to use Ref objects. They are mostly useful only when your macro is running slowly because it’s unnecessarily copying arrays or hashes, or when dealing with nested data structures.

That's for the benefit of anyone else reading this discussion, as generally you don't need to use or know about Refs when writing macros.

Presumably NWP text objects are immutables, and an array is (something like) a linked list. So every change to a text object really does create a brand new object and the linked list is just updated to have its (in this case 4th) item point to the new object

The top part of the code actually uses two Text objects. A copy is implicitly made during the assignment of the $modified variable.
The bottom part of the code sidesteps the copy by wrapping the Text object in a Ref.

That example is of course very contrived. You're more likely to use Refs if you need to pass objects around to custom commands (user defined functions). The macro reference goes into some detail describing why you might want to use Refs to wrap hashes or arrays, so they aren't copied as you pass them around between functions.

Text objects are also somewhat special in that they inherently sometimes use value semantics and other times use reference semantics. This is described in the macro reference's Text object documentation under "Storage Semantics". This is potentially confusing when trying to understand the inner workings of macros, but generally behaves correctly when you consider how text objects can originate differently. Some text objects are unique and it's less likely that you want to copy them and thus should use reference semantics (eg: a document's main text object), while other text objects are anonymous and ephemeral like the example string "hello" and thus should generally be copied.

Text objects that already use reference semantics don't need to be wrapped in a Ref. For those text objects you actually have the opposite problem: you might need to force an explicit copy if you don't want to modify the original text, eg: