# Why is the function of a callable object (Functor) allocating?

**URL:** https://discourse.julialang.org/t/why-is-the-function-of-a-callable-object-functor-allocating/57773
**Category:** General Usage
**Tags:** memory-allocation, functors
**Created:** [March 23, 2021, 8:14am UTC](https://discourse.julialang.org/t/why-is-the-function-of-a-callable-object-functor-allocating/57773 "2021-03-23T08:14:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zsoerenm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zsoerenm/32/664_2.png) [@zsoerenm](https://discourse.julialang.org/u/zsoerenm)
#### Post date: [March 23, 2021, 8:14am UTC](https://discourse.julialang.org/t/why-is-the-function-of-a-callable-object-functor-allocating/57773/1 "2021-03-23T08:14:18Z")

</div>

I’m experimenting with functors. I noticed that when I pass an array to the functor, that it is allocating memory even if it should be possible without memory allocation.  
Here is a simplified version:

```julia
struct Foo end
(::Foo)(x) = sum(x)
foo = Foo()
a = randn(10)
@btime foo($a) # 19.765 ns (1 allocation: 16 bytes)
@btime sum($a) # 5.792 ns (0 allocations: 0 bytes)

```

Why is `foo($a)` allocating memory?

In case that it matters: I’m using Julia 1.5.3

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [March 23, 2021, 8:21am UTC](https://discourse.julialang.org/t/why-is-the-function-of-a-callable-object-functor-allocating/57773/2 "2021-03-23T08:21:10Z")

</div>

Because your `foo` is not `const`. So use a `$` on in too:

```julia
julia> @btime $foo($a)
  3.701 ns (0 allocations: 0 bytes)
4.349093588060725

```
