# What are the "...toRef" Methods? How Should We Use Them?

**URL:** <https://forum.babylonjs.com/t/what-are-the-toref-methods-how-should-we-use-them/8434>\
**Category:** Questions\
**Created:** [February 5, 2020, 3:12pm UTC](https://forum.babylonjs.com/t/what-are-the-toref-methods-how-should-we-use-them/8434 "2020-02-05T15:12:46Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [February 5, 2020, 4:20pm UTC](https://forum.babylonjs.com/t/what-are-the-toref-methods-how-should-we-use-them/8434/4 "2020-02-05T16:20:49Z")

</div>

To expand a little more on @sebavan and @Deltakosh 's comments

In your question you show ‘toRef’ with only one parameter.

> [@SpaceToast](#):
>
> added “to ref”–myVect.addToRef(myOtherVect)

It requires two parameters, the vector to add and a results vector in which the addition is stored.

This (rather implausible) example shows the benefit of ‘toRef’ over the basic

There is a line of points along the x axis and from each point we need to draw a random unit vector. We achieve this for each point A by generating a random point B and forming the unit vector from A to B.

Method 1 - GC (garbage collection) rich

```Javacscript
for (var i = 0; i < 10; i++) {
    var A = new BABYLON.Vector3(2 * i, 0, 0);
    var B = new BABYLON.Vector3(Math.random(), Math.random(), Math.random());
    B.normalize();
    var C = A.add(B);
    // draw line from A to C

```

Method 2 -GC light

```javascript
var A = BABYLON.Vector3.Zero();
var B = BABYLON.Vector3.Zero();
var C = BABYLON.Vector3.Zero();
for (var i = 0; i < 10; i++) {
    A.x = 2 * i;
    B.set(Math.random(), Math.random(), Math.random());
    B.normalize();
    A.addToRef(B, C);
    // draw line from A to C
}

```

---

_[View the full topic](https://forum.babylonjs.com/t/what-are-the-toref-methods-how-should-we-use-them/8434)._
